https://www.acmicpc.net/problem/1614
using System;
class Program
{
static void Main() {
string s=Console.ReadLine();
string s1=Console.ReadLine();
long n=int.Parse(s);
long m=int.Parse(s1);
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;
}
Console.Write(num);
}
}