#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, k, j;
  k = a;
  j = 0;
  while (1) {
    cin >> a >> b >> c;
    if (c % k == 0) {
      j += 1;
    }
    if (k == b) break;
    k += 1;
  }
  cout << k << endl;
  return 0;
}
