#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 3010;
long long a[N], b[N], c[N], d[N], e[N], f[N];
vector<long long> x, y;
long long n, m, h, w;
long long s[N][N];
long long F[N][N];
long long xline[N], yline[N];
long long cx[4] = {0, 1, 0, -1};
long long cy[4] = {1, 0, -1, 0};
long long ok(long long x, long long y) {
  return 0 <= x && x < w && 0 <= y && y < h && F[y][x] == 0;
}
void demon() {
  return;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cout << F[i][j];
    }
    cout << "\n";
  }
}
long long Sq(long long i, long long j) {
  if (i % 2 == 0 && j % 2 == 0) {
    return (xline[j + 1] - xline[j - 1]) * (yline[i + 1] - yline[i - 1]);
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  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]);
    y.push_back(e[i]);
    y.push_back(f[i]);
  }
  x.push_back(0);
  y.push_back(0);
  sort((x).begin(), (x).end());
  x.resize(unique((x).begin(), (x).end()) - x.begin());
  sort((y).begin(), (y).end());
  y.resize(unique((y).begin(), (y).end()) - y.begin());
  for (long long i = 0; i < x.size(); i++) {
    xline[2 * i + 1] = x[i];
  }
  for (long long i = 0; i < y.size(); i++) {
    yline[2 * i + 1] = y[i];
  }
  h = x.size() * 2 + 1;
  w = y.size() * 2 + 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 1; j < w; j += 2) {
      if (yline[j] == c[i]) {
        long long t = 0;
        for (long long k = 0; k < h; k++) {
          if (k % 2 == 1 && xline[k] == a[i]) t = 1;
          if (t) F[k][j] = 1;
          if (k % 2 == 1 && xline[k] == b[i]) t = 0;
        }
      }
    }
  }
  demon();
  for (long long i = 0; i < m; i++) {
    for (long long j = 1; j < h; j += 2) {
      if (xline[j] == d[i]) {
        long long t = 0;
        for (long long k = 0; k < w; k++) {
          if (k % 2 == 1 && yline[k] == e[i]) t = 1;
          if (t) F[j][k] = 1;
          if (k % 2 == 1 && yline[k] == f[i]) t = 0;
        }
      }
    }
  }
  demon();
  vector<pair<long long, long long> > s;
  long long ans = 0;
  for (long long i = 1; i < w; i += 2)
    for (long long j = 1; j < h; j += 2)
      if (yline[i] == 0 && xline[j] == 0)
        s.push_back({i, j}), ans += Sq(i, j), F[j][i] = 2;
  for (long long i = 0; i < s.size(); i++) {
    for (long long k = 0; k < 4; k++) {
      long long nx = s[i].first + cx[k];
      long long ny = s[i].second + cy[k];
      if (ok(nx, ny)) {
        if (nx == 0 || nx == w - 1 || ny == 0 || ny == h - 1)
          cout << "INF", exit(0);
        s.push_back({nx, ny});
        ans += Sq(nx, ny);
        F[ny][nx] = 2;
      }
    }
  }
  demon();
  cout << ans;
}
