using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ForYukicoder { class Program { static void Main(string[] args) { string[] str = new string[2]; int[] X = new int[3]; int[] Y = new int[3]; for (int i = 0; i < 3; i++) { str = Console.ReadLine().Split(); X[i] = int.Parse(str[0]); Y[i] = int.Parse(str[1]); } //---------------- for (int a = 0; a < 1000000; a++) { if (a % Y[0] == X[0] && a % Y[1] == X[1] && a % Y[2] == X[2]) { Console.WriteLine(a); return; } } Console.WriteLine(-1); } } }