#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
vector<T> compress(vector<T> A) {
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  return A;
}
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(n), c(n);
  vector<long long> d(m), e(m), f(m);
  vector<long long> X, Y;
  for (long long i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    X.push_back(a[i]);
    X.push_back(b[i]);
    Y.push_back(c[i]);
  }
  for (long long i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    X.push_back(d[i]);
    X.push_back(e[i]);
    Y.push_back(f[i]);
  }
  X.push_back(0);
  Y.push_back(0);
  X.push_back(INF);
  Y.push_back(INF);
  X.push_back(-INF);
  Y.push_back(-INF);
  auto comx = compress(X);
  auto comy = compress(Y);
  long long xsz = (long long)comx.size(), ysz = (long long)comy.size();
  vector<vector<long long>> mv0(ysz + 1, vector<long long>(xsz + 1, 0)),
      mv1(xsz + 1, vector<long long>(ysz + 1, 0)),
      mv2(ysz + 1, vector<long long>(xsz + 1)),
      mv3(xsz + 1, vector<long long>(ysz + 1, 0));
  for (long long i = 0; i < n; i++) {
    long long cy =
        lower_bound(comy.begin(), comy.end(), (c[i])) - (comy).begin();
    ;
    long long ax =
        lower_bound(comx.begin(), comx.end(), (a[i])) - (comx).begin();
    ;
    long long bx =
        lower_bound(comx.begin(), comx.end(), (b[i])) - (comx).begin();
    ;
    mv3[ax][cy]++, mv3[bx][cy]--;
    mv1[ax][cy - 1]++, mv1[bx][cy - 1]--;
  }
  for (long long i = 0; i < m; i++) {
    long long dxx =
        lower_bound(comx.begin(), comx.end(), (d[i])) - (comx).begin();
    ;
    long long ey =
        lower_bound(comy.begin(), comy.end(), (e[i])) - (comy).begin();
    ;
    long long fy =
        lower_bound(comy.begin(), comy.end(), (f[i])) - (comy).begin();
    ;
    mv2[dxx][ey]++;
    mv2[dxx][fy]--;
    mv0[dxx - 1][ey]++;
    mv0[dxx - 1][fy]--;
  }
  for (long long i = 0; i < xsz; i++) {
    for (long long j = 0; j < ysz + 1; j++) {
      mv1[i + 1][j] += mv1[i][j];
      mv3[i + 1][j] += mv3[i][j];
    }
  }
  for (long long i = 0; i < xsz + 1; i++) {
    for (long long j = 0; j < ysz; j++) {
      mv0[i][j + 1] += mv0[i][j];
      mv2[i][j + 1] += mv2[i][j];
    }
  }
  queue<pair<long long, long long>> que;
  map<pair<long long, long long>, long long> dist;
  for (long long i = 0; i < xsz; i++) {
    for (long long j = 0; j < ysz; j++) {
      dist[{i, j}] = INF;
    }
  }
  long long stx = lower_bound(comx.begin(), comx.end(), (0)) - (comx).begin();
  ;
  long long sty = lower_bound(comy.begin(), comy.end(), (0)) - (comy).begin();
  ;
  dist[{stx, sty}] = 0;
  dist[{stx - 1, sty}] = 0;
  dist[{stx, sty - 1}] = 0;
  dist[{stx - 1, sty - 1}] = 0;
  que.push({stx, sty});
  que.push({stx - 1, sty});
  que.push({stx, sty - 1});
  que.push({stx - 1, sty - 1});
  while (!que.empty()) {
    pair<long long, long long> p = que.front();
    que.pop();
    long long x = p.first, y = p.second;
    long long nx0 = x + dx[0], ny0 = y + dy[0];
    if (0 <= nx0 && nx0 < xsz && 0 <= ny0 && ny0 < ysz) {
      if (chmin(dist[{nx0, ny0}], dist[{x, y}] + 1) && !mv0[nx0][ny0]) {
        que.push({nx0, ny0});
      }
    }
    long long nx1 = x + dx[1], ny1 = y + dy[1];
    if (0 <= nx1 && nx1 < xsz && 0 <= ny1 && ny1 < ysz && !mv1[nx1][ny1]) {
      if (chmin(dist[{nx1, ny1}], dist[{x, y}] + 1)) {
        que.push({nx1, ny1});
      }
    }
    long long nx2 = x + dx[2], ny2 = y + dy[2];
    if (0 <= nx2 && nx2 < xsz && 0 <= ny2 && ny2 < ysz && !mv2[nx2][ny2]) {
      if (chmin(dist[{nx2, ny2}], dist[{x, y}] + 1)) {
        que.push({nx2, ny2});
      }
    }
    long long nx3 = x + dx[3], ny3 = y + dy[3];
    if (0 <= nx3 && nx3 < xsz && 0 <= ny3 && ny3 < ysz && !mv3[nx3][ny3]) {
      if (chmin(dist[{nx0, ny0}], dist[{x, y}] + 1)) {
        que.push({nx0, ny0});
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < xsz; i++) {
    for (long long j = 0; j < ysz; j++) {
      if (i == 0 || j == 0 || i == xsz - 1 || j == ysz - 1) {
        if (dist[{i, j}] < INF) {
          cout << "INF" << endl;
          return;
        }
      } else {
        if (dist[{i, j}] < INF) {
          ans += (X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);
        }
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
