#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int a[1005], b[1005], c[1005], d[1005], e[1005], f[1005], ln, lm, ans;
bool vis[3005][3005], w[3005][3005][4], le[3005][3005], hi[3005][3005];
int fx[4][2] = {0, -1, 0, 1, 1, 0, -1, 0};
void dfs(int x, int y) {
  if (!x || !y || x >= lm || y >= ln) {
    cout << "INF";
    exit(0);
  }
  int tx, ty;
  ans += le[x][y] * hi[x][y];
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    if (!w[x][y][i]) {
      tx = x + fx[i][0];
      ty = y + fx[i][1];
      if (!vis[tx][ty]) dfs(tx, ty);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  vector<int> vn, vm;
  cin >> n >> m;
  vn.emplace_back(0);
  vm.emplace_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    vn.emplace_back(a[i]);
    vn.emplace_back(b[i]);
    vm.emplace_back(c[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    vn.emplace_back(d[i]);
    vm.emplace_back(e[i]);
    vm.emplace_back(f[i]);
  }
  sort(vn.begin(), vn.end());
  vn.erase(unique(vn.begin(), vn.end()), vn.end());
  ln = vn.size();
  sort(vm.begin(), vm.end());
  vm.erase(unique(vm.begin(), vm.end()), vm.end());
  lm = vm.size();
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(vn.begin(), vn.end(), a[i]) - vn.begin();
    b[i] = lower_bound(vn.begin(), vn.end(), b[i]) - vn.begin();
    c[i] = lower_bound(vm.begin(), vm.end(), c[i]) - vm.begin();
    for (int j = a[i] + 1; j <= b[i]; j++) {
      w[c[i]][j][2] = 1;
      w[c[i] + 1][j][3] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    d[i] = lower_bound(vn.begin(), vn.end(), d[i]) - vn.begin();
    e[i] = lower_bound(vm.begin(), vm.end(), e[i]) - vm.begin();
    f[i] = lower_bound(vm.begin(), vm.end(), f[i]) - vm.begin();
    for (int j = e[i] + 1; j <= f[i]; j++) {
      w[j][d[i]][1] = 1;
      w[j][d[i] + 1][0] = 1;
    }
  }
  for (int i = 1; i < ln; i++) {
    for (int j = 1; j < lm; j++) {
      le[j][i] = vn[i] - vn[i - 1];
      hi[i][j] = vm[j] - vm[j - 1];
    }
  }
  dfs(lower_bound(vm.begin(), vm.end(), 0) - vm.begin() + 1,
      lower_bound(vn.begin(), vn.end(), 0) - vn.begin() + 1);
  cout << ans;
  return 0;
}
