#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, N = 4010;
int a[N], b[N], c[N], d[N], e[N], f[N];
bool l[N][N], r[N][N], u[N][N], dd[N][N];
bool vis[N][N];
int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<int> xs({-INF, INF}), ys({-INF, INF});
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    if (i == 0 && u[x][y]) continue;
    if (i == 1 && dd[x][y]) continue;
    if (i == 2 && r[x][y]) continue;
    if (i == 3 && l[x][y]) continue;
    int xx = x + dir[i][0];
    int yy = y + dir[i][1];
    if (xx < 0 || yy < 0) continue;
    if (xx >= xs.size() - 1 || yy >= ys.size() - 1) continue;
    if (vis[xx][yy]) continue;
    dfs(xx, yy);
  }
}
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> 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++) {
    cin >> 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());
  sort((ys).begin(), (ys).end());
  xs.resize(unique((xs).begin(), (xs).end()) - xs.begin());
  ys.resize(unique((ys).begin(), (ys).end()) - ys.begin());
  int x = lower_bound((xs).begin(), (xs).end(), 0) - xs.begin();
  int y = lower_bound((ys).begin(), (ys).end(), 0) - ys.begin();
  x--, y--;
  for (int i = 0; i < n; i++) {
    int aa = lower_bound((xs).begin(), (xs).end(), a[i]) - xs.begin();
    int bb = lower_bound((xs).begin(), (xs).end(), b[i]) - xs.begin();
    int cc = lower_bound((ys).begin(), (ys).end(), c[i]) - ys.begin();
    for (int j = aa; j < bb; j++) {
      u[j][cc - 1] = 1;
      dd[j][cc] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    int ddd = lower_bound((xs).begin(), (xs).end(), d[i]) - xs.begin();
    int ee = lower_bound((ys).begin(), (ys).end(), e[i]) - ys.begin();
    int ff = lower_bound((ys).begin(), (ys).end(), f[i]) - ys.begin();
    for (int j = ee; j < ff; j++) {
      r[ddd - 1][j] = 1;
      l[ddd][j] = 1;
    }
  }
  dfs(x, y);
  if (vis[0][0] || vis[xs.size() - 1][ys.size() - 1]) {
    cout << "INF" << endl;
    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 (vis[i][j]) {
        ans += (long long)(xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
      }
    }
  }
  cout << ans << endl;
}
