m1097 = 1000000007

main = do
  [n, m] <- map read . words <$> getLine
  putStrLn . show $ solve n m

solve:: Int -> Int -> Int
solve n m
  | n == m = mu poN $ mu poN 2
  | abs (n - m) /= 1 = 0
  | otherwise = mu poN $ po m
  where
    poN = po n

po 0 = 1
po a = mu a $ po (a - 1)

mu a b = mod ((mod a m1097) * (mod b m1097)) m1097
