#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
  return a = (a > b) ? b : a;
}
long long const INF = 1LL << 60;
long long const MOD = 1000000007;
const long long MAX_X = 1010;
const long long MAX_Y = 1010;
long long v_line[MAX_X][MAX_Y];
long long h_line[MAX_X][MAX_Y];
bool vis[MAX_X][MAX_Y];
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  long long N, M;
  cin >> N >> M;
  vector<long long> A(N), B(N), C(N), D(M), E(M), F(M);
  for (long long i = 0; i < (N); i++) {
    cin >> A[i] >> B[i] >> C[i];
  }
  for (long long i = 0; i < (M); i++) {
    cin >> D[i] >> E[i] >> F[i];
  }
  vector<long long> x_dict, y_dict;
  x_dict.push_back(-INF);
  x_dict.push_back(INF);
  x_dict.push_back(0);
  y_dict.push_back(-INF);
  y_dict.push_back(INF);
  y_dict.push_back(0);
  for (long long i = 0; i < (N); i++) {
    x_dict.push_back(A[i]);
    x_dict.push_back(B[i]);
    y_dict.push_back(C[i]);
  }
  for (long long i = 0; i < (M); i++) {
    x_dict.push_back(D[i]);
    y_dict.push_back(E[i]);
    y_dict.push_back(F[i]);
  }
  sort((x_dict).begin(), (x_dict).end());
  x_dict.erase(unique((x_dict).begin(), (x_dict).end()), x_dict.end());
  sort((y_dict).begin(), (y_dict).end());
  y_dict.erase(unique((y_dict).begin(), (y_dict).end()), y_dict.end());
  long long W = ((int)(x_dict).size());
  long long H = ((int)(y_dict).size());
  for (long long i = 0; i < (N); i++) {
    int a =
        lower_bound((x_dict).begin(), (x_dict).end(), A[i]) - x_dict.begin();
    int b =
        lower_bound((x_dict).begin(), (x_dict).end(), B[i]) - x_dict.begin();
    int c =
        lower_bound((y_dict).begin(), (y_dict).end(), C[i]) - y_dict.begin();
    v_line[c][a]++;
    v_line[c][b]--;
  }
  for (long long i = 0; i < (M); i++) {
    int d =
        lower_bound((x_dict).begin(), (x_dict).end(), D[i]) - x_dict.begin();
    int e =
        lower_bound((y_dict).begin(), (y_dict).end(), E[i]) - y_dict.begin();
    int f =
        lower_bound((y_dict).begin(), (y_dict).end(), F[i]) - y_dict.begin();
    h_line[e][d]++;
    h_line[f][d]--;
  }
  for (long long y = 0; y < (H); y++)
    for (long long x = (1); x < (W); x++) v_line[y][x] += v_line[y][x - 1];
  for (long long x = 0; x < (W); x++)
    for (long long y = (1); y < (H); y++) h_line[y][x] += h_line[y - 1][x];
  long long res = 0;
  queue<pair<long long, long long>> que;
  long long stx =
      lower_bound((x_dict).begin(), (x_dict).end(), 0) - x_dict.begin();
  long long sty =
      lower_bound((y_dict).begin(), (y_dict).end(), 0) - y_dict.begin();
  vis[sty][stx] = true;
  que.push({stx, sty});
  while (!que.empty()) {
    long long ix, iy;
    tie(ix, iy) = que.front();
    que.pop();
    if (ix == 0 || ix == W - 1) {
      res = INF;
      break;
    }
    if (iy == 0 || iy == H - 1) {
      res = INF;
      break;
    }
    res += (x_dict[ix + 1] - x_dict[ix]) * (y_dict[iy + 1] - y_dict[iy]);
    for (long long d = 0; d < (4); d++) {
      long long ix2 = ix + dx[d];
      long long iy2 = iy + dy[d];
      if (0 <= ix2 && ix2 < W && 0 <= iy2 && iy2 < H && !vis[iy2][ix2]) {
        if (ix == ix2) {
          if (v_line[max(iy, iy2)][ix2]) continue;
        } else {
          if (h_line[iy][max(ix, ix2)]) continue;
        }
        vis[iy2][ix2] = true;
        que.push({ix2, iy2});
      }
    }
  }
  if (res == INF)
    cout << "INF" << endl;
  else
    cout << res << endl;
  return 0;
}
