#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;

static const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
  map<int, int> hm, vm;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i], &b[i] ,&c[i]);
    hm.insert({a[i], 0});
    hm.insert({b[i], 0});
    vm.insert({c[i], 0});
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &d[i], &e[i], &f[i]);
    hm.insert({d[i], 0});
    vm.insert({e[i], 0});
    vm.insert({f[i], 0});
  }

  vector<int> h(hm.size()), v(vm.size());
  int counter = 0;
  for (auto p : hm) {
    h[counter] = p.first;
    hm[p.first] = counter++;
  }
  counter = 0;
  for (auto p : vm) {
    v[counter] = p.first;
    vm[p.first] = counter++;
  }

  vector<vector<vector<bool>>> connect(h.size() + 1, vector<vector<bool>>(v.size() + 1, vector<bool>(4, true)));
  for (int i = 0; i < n; i++) {
    int s = hm[a[i]], t = hm[b[i]], u = vm[c[i]];
    for (int j = s; j < t; j++) {
      connect[j + 1][u][1] = false;
      connect[j + 1][u + 1][3] = false;
    }
  }
  for (int i = 0; i < m; i++) {
    int s = vm[e[i]], t = vm[f[i]], u = hm[d[i]];
    for (int j = s; j < t; j++) {
      connect[u][j + 1][0] = false;
      connect[u + 1][j + 1][2] = false;
    }
  }

  queue<pair<int, int>> q;
  int x0 = 0, y0 = 0;
  for (int i = 0; i < h.size(); i++)
    if (h[i] >= 0) {
      x0 = i;
      break;
    }
  for (int i = 0; i < v.size(); i++)
    if (v[i] >= 0) {
      y0 = i;
      break;
    }
  q.push({x0, y0});

  vector<vector<bool>> visited(h.size() + 1, vector<bool>(v.size() + 1));
  visited[x0][y0] = true;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();

    int x = p.first, y = p.second;
    for (int i = 0; i < 4; i++)
      if (connect[x][y][i]) {
        int xx = x + dir[i][0], yy = y + dir[i][1];
        if (xx >= 0 && xx <= h.size() && yy >= 0 && yy <= v.size() && !visited[xx][yy]) {
          visited[xx][yy] = true;
          q.push({xx, yy});
        }
      }
  }

  bool inf = false;
  long long ans = 0;
  for (int i = 0; i <= h.size(); i++)
    for (int j = 0; j <= v.size(); j++)
      if (visited[i][j]) {
        if (i == 0 || i == h.size() || j == 0 || j == v.size())
          inf = true;
        else
          ans += 1LL * (h[i] - h[i - 1]) * (v[j] - v[j - 1]);
      }

  if (inf)
    printf("INF\n");
  else
    printf("%lld\n", ans);

  return 0;
}