# Arup Guha
# 11/8/2025
# Solution to Shared D1/D2 Problem M: Much Room for Mushrooms

toks = input().split()

r = int(toks[0])
c = int(toks[1])

# This can't be done.
if r >= 3 and c >= 3:
    print(-1)

# One tall mushroom.
elif c == 1:
    print(1)

# Go across, horizontal, putting together triples.
elif r == 1:
    print( (c+2)//3 )

# Long rectangle, horizontal.
elif r == 2:
    print(c//2+1)

# My last case.
elif c == 2:
    print(-1)






