main = do
  [t1, t2] <- map read . words <$> getLine
  [a1, a2] <- map read . words <$> getLine
  [b1, b2] <- map read . words <$> getLine
  putStrLn $ solve [t1,t2] [a1,a2] [b1,b2]

solve :: [Int] -> [Int] -> [Int] -> String
solve ts as bs
  | da == db = "infinity"
  | otherwise = show . length . takeWhile id $ zipWith encount compared (tail compared)
  where
   seriesA = scanl1 (+) $ cycle (zipWith (*) ts as)
   seriesB = scanl1 (+) $ cycle (zipWith (*) ts bs)
   compared = zipWith compare seriesA seriesB
   da = sum $ zipWith (*) ts as
   db = sum $ zipWith (*) ts bs
   encount EQ _ = False
   encount x y = x /= y