https://www.acmicpc.net/problem/1614
n=int(input()) m=int(input()) num=0 if n==1: num+=8*m elif n==5: num+=8*m+4 else: if m%2==1: num+=5-n else: num+=n-1 num+=4*m print(num)