#include <bits/stdc++.h>
using namespace std;
int a[1005], b[1005], c[1005], d[1005], e[1005], f[1005];
int u[1005][1005], dd[1005][1005], l[1005][1005], r[1005][1005];
bool vis[1005][1005];
int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<int> xs({-1000000007, 1000000007}), ys({-1000000007, 1000000007});
queue<pair<int, int> > q;
void BFS(int x, int y) {
  q.push({x, y});
  vis[x][y] = 1;
  while (!q.empty()) {
    int xi = q.front().first, yi = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      if (i == 0 and u[xi][yi]) continue;
      if (i == 1 and dd[xi][yi]) continue;
      if (i == 2 and r[xi][yi]) continue;
      if (i == 3 and l[xi][yi]) continue;
      int xii = xi + dir[i][0], yii = yi + dir[i][1];
      if (xii < 0 or yii < 0 or xii >= xs.size() - 1 or yii >= ys.size() - 1)
        continue;
      if (vis[xii][yii]) continue;
      vis[xii][yii] = 1;
      q.push({xii, yii});
    }
  }
}
int main() {
  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(), y;
  y = lower_bound((ys).begin(), (ys).end(), 0) - ys.begin();
  x--, y--;
  for (int i = 0; i < n; i++) {
    int ai = lower_bound((xs).begin(), (xs).end(), a[i]) - xs.begin(), bi, ci;
    bi = lower_bound((xs).begin(), (xs).end(), b[i]) - xs.begin();
    ci = lower_bound((ys).begin(), (ys).end(), c[i]) - ys.begin();
    for (int j = ai; j < bi; j++) {
      u[j][ci - 1] = 1;
      dd[j][ci] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    int di = lower_bound((xs).begin(), (xs).end(), d[i]) - xs.begin(), ei, fi;
    ei = lower_bound((ys).begin(), (ys).end(), e[i]) - ys.begin();
    fi = lower_bound((ys).begin(), (ys).end(), f[i]) - ys.begin();
    for (int j = ei; j < fi; j++) {
      r[di - 1][j] = 1;
      l[di][j] = 1;
    }
  }
  BFS(x, y);
  if (vis[0][0] or vis[xs.size() - 1][ys.size() - 1]) {
    cout << "INF"
         << "\n";
    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 = (ans + (xs[i + 1] - xs[i]) * 1LL * (ys[j + 1] - ys[j]));
  }
  cout << ans << "\n";
  return 0;
}
