import java.util.*;
public class xiaowuc1 {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int c = sc.nextInt();
    if(r == 1) System.out.println((c+2)/3);
    else if(r == 2) System.out.println(c/2+1);
    else if(c == 1) System.out.println(1);
    else System.out.println(-1);
  }
}
