https://www.acmicpc.net/problem/1614
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
long n=s.nextInt();
long m=s.nextInt();
long num=0;
if(n==1) num+=8*m;
else if(n==5) num+=8*m+4;
else{
if(m%2==1) num+=5-n;
else num+=n-1;
num+=4*m;
}
System.out.print(num);
}
}