#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
int n, m;
int a[2000], b[2000], c[2000], d[2000], e[2000], f[2000];
int sum1[3000][3000], sum2[3000][3000];
int dist[3000][3000];
int lwb(vector<int>& v, int x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
int ok(int x, int y, int d) {
  if (d == 0) {
    return sum2[x + 1][y] == 0;
  } else if (d == 1) {
    return sum2[x][y] == 0;
  } else if (d == 2) {
    return sum1[x][y + 1] == 0;
  } else {
    return sum1[x][y] == 0;
  }
}
int main() {
  cin >> n >> m;
  vector<int> xs, ys;
  xs.push_back(0);
  ys.push_back(0);
  xs.push_back(-2e9);
  xs.push_back(2e9);
  ys.push_back(-2e9);
  ys.push_back(2e9);
  for (int i = 0; i < (n); i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    xs.push_back(a[i]);
    xs.push_back(b[i]);
    ys.push_back(c[i]);
  }
  for (int i = 0; i < (m); i++) {
    scanf("%d%d%d", &d[i], &e[i], &f[i]);
    xs.push_back(d[i]);
    ys.push_back(e[i]);
    ys.push_back(f[i]);
  }
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  sort(ys.begin(), ys.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  for (int i = 0; i < (n); i++) {
    a[i] = lwb(xs, a[i]);
    b[i] = lwb(xs, b[i]);
    c[i] = lwb(ys, c[i]);
    sum1[a[i]][c[i]]++;
    sum1[b[i]][c[i]]--;
  }
  for (int i = 0; i < (m); i++) {
    d[i] = lwb(xs, d[i]);
    e[i] = lwb(ys, e[i]);
    f[i] = lwb(ys, f[i]);
    sum2[d[i]][e[i]]++;
    sum2[d[i]][f[i]]--;
  }
  for (int i = 0; i < (xs.size() + 1); i++) {
    for (int j = 0; j < (ys.size() + 1); j++) {
      if (i) sum1[i][j] += sum1[i - 1][j];
      if (j) sum2[i][j] += sum2[i][j - 1];
    }
  }
  queue<pair<int, int> > que;
  memset(dist, -1, sizeof(dist));
  int sx = lwb(xs, 0), sy = lwb(ys, 0);
  dist[sx][sy] = 0;
  que.push(pair<int, int>(sx, sy));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int k = 0; k < (4); k++) {
      int nx = p.first + dx[k], ny = p.second + dy[k];
      if (0 <= nx && nx < xs.size() - 1 && 0 <= ny && ny < ys.size() - 1 &&
          dist[nx][ny] == -1 && ok(p.first, p.second, k)) {
        dist[nx][ny] = dist[sx][sy] + 1;
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
  if (dist[0][0] != -1) {
    puts("INF");
    return 0;
  }
  long long ans = 0;
  for (int i = 0; i < (xs.size() - 1); i++)
    for (int j = 0; j < (ys.size() - 1); j++) {
      if (dist[i][j] != -1) {
        long long h = xs[i + 1] - xs[i], w = ys[j + 1] - ys[j];
        ans += h * w;
      }
    }
  cout << ans << endl;
}
