#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
ll area[2020][2020];
int ng[2020][2020][4];
int used[2020][2020];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(m), e(m), f(m), x, y;
  x.push_back(0);
  y.push_back(0);
  for (int 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 (int 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]);
  }
  sort((x).begin(), (x).end());
  sort((y).begin(), (y).end());
  x.erase(unique((x).begin(), (x).end()), x.end());
  y.erase(unique((y).begin(), (y).end()), y.end());
  int sx = x.size(), sy = y.size();
  map<int, int> get_x, get_y;
  for (int i = 0; i < sx; i++) {
    get_x[x[i]] = i;
  }
  for (int i = 0; i < sy; i++) {
    get_y[y[i]] = i;
  }
  for (int i = 0; i < sx - 1; i++)
    for (int j = 0; j < sy - 1; j++)
      area[i][j] = (ll)(x[i + 1] - x[i]) * (ll)(y[i + 1] - y[i]);
  for (int i = 0; i < n; i++) {
    int yid = get_y[c[i]];
    int l = get_x[a[i]], r = get_x[b[i]];
    for (int xid = l; xid < r; xid++) {
      if (yid > 0) {
        ng[xid][yid - 1][3] = 1;
      }
      if (yid < sy - 1) {
        ng[xid][yid][1] = 1;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int xid = get_x[d[i]];
    int l = get_y[e[i]], r = get_y[f[i]];
    for (int yid = l; yid < r; yid++) {
      if (xid > 0) {
        ng[xid - 1][yid][0] = 1;
      }
      if (xid < sx - 1) {
        ng[xid][yid][2] = 1;
      }
    }
  }
  ll ans = 0;
  int cnt = 0;
  {
    int x = get_x[0], y = get_y[0];
    queue<pair<int, int>> Q;
    Q.emplace(x, y);
    while (Q.size()) {
      cnt++;
      assert(cnt <= 1e7);
      auto e = Q.front();
      Q.pop();
      x = e.first, y = e.second;
      ans += area[x][y];
      used[x][y] = 1;
      for (int dir = 0; dir < 4; dir++) {
        int nx = x + dx[dir];
        int ny = y + dy[dir];
        if (!ng[x][y][dir]) {
          auto inner = [=](int x, int y) {
            return x >= 0 && x < sx - 1 && y >= 0 && y < sy - 1;
          };
          if (!inner(nx, ny)) {
            cout << "INF" << '\n';
            return 0;
          } else {
            if (!used[nx][ny]) Q.emplace(nx, ny);
          }
        }
      }
    }
  }
  cout << ans - 1 << '\n';
  return 0;
}
