#include <bits/stdc++.h>
using namespace std;
const long long N = 12007, inf = 0x3f3f3f3f;
void fly() {
  cout << "INF\n";
  exit(0);
}
char bad[N][N];
char vis[N][N];
vector<pair<long long, long long> > moves = {
    {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> I, J;
  vector<pair<pair<long long, long long>, pair<long long, long long> > > hor,
      ver;
  for (long long i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a *= 2, b *= 2, c *= 2;
    ver.emplace_back(make_pair(a, c), make_pair(b, c));
    I.push_back(a - 1);
    I.push_back(a);
    I.push_back(a + 1);
    I.push_back(b - 1);
    I.push_back(b);
    I.push_back(b + 1);
    J.push_back(c);
    J.push_back(c + 1);
    J.push_back(c - 1);
  }
  for (long long i = 0; i < m; i++) {
    long long d, e, f;
    cin >> d >> e >> f;
    d *= 2, e *= 2, f *= 2;
    hor.emplace_back(make_pair(d, e), make_pair(d, f));
    J.push_back(e - 1);
    J.push_back(e);
    J.push_back(e + 1);
    J.push_back(f - 1);
    J.push_back(f);
    J.push_back(f + 1);
    I.push_back(d - 1);
    I.push_back(d);
    I.push_back(d + 1);
  }
  I.push_back(0);
  J.push_back(0);
  sort(I.begin(), I.end());
  I.erase(unique(I.begin(), I.end()), I.end());
  sort(J.begin(), J.end());
  J.erase(unique(J.begin(), J.end()), J.end());
  for (long long k = 0; k < n; ++k) {
    long long p, q;
    tie(p, q) = ver[k].first;
    long long i = lower_bound(I.begin(), I.end(), p) - I.begin();
    long long j = lower_bound(J.begin(), J.end(), q) - J.begin();
    tie(p, q) = ver[k].second;
    for (; I[i] != p or J[j] != q; i++) {
      bad[i][j] = true;
    }
    bad[i][j] = true;
  }
  for (long long k = 0; k < m; ++k) {
    long long p, q;
    tie(p, q) = hor[k].first;
    long long i = lower_bound(I.begin(), I.end(), p) - I.begin();
    long long j = lower_bound(J.begin(), J.end(), q) - J.begin();
    tie(p, q) = hor[k].second;
    for (; I[i] != p or J[j] != q; j++) {
      bad[i][j] = true;
    }
    bad[i][j] = true;
  }
  n = I.size();
  m = J.size();
  long long p, q;
  p = lower_bound(I.begin(), I.end(), 0) - I.begin();
  q = lower_bound(J.begin(), J.end(), 0) - J.begin();
  assert(bad[p][q] == false);
  queue<pair<long long, long long> > qu;
  qu.push({p, q});
  vis[p][q] = 1;
  while (qu.size()) {
    long long i, j;
    tie(i, j) = qu.front();
    qu.pop();
    for (pair<long long, long long> aux : moves) {
      long long u = i + aux.first;
      long long v = j + aux.second;
      if (u >= 0 and u < n and j >= 0 and j < m) {
        if (!vis[u][v]) {
          vis[u][v] = 1;
          if (!bad[u][v]) qu.push({u, v});
        }
      } else {
        fly();
      }
    }
  }
  long long area = 0;
  for (long long i = 1; i < n; ++i) {
    for (long long j = 1; j < m; ++j) {
      if (vis[i][j] and vis[i - 1][j] and vis[i][j - 1] and vis[i - 1][j - 1]) {
        area += (I[i] - I[i - 1]) * (J[j] - J[j - 1]) / 4;
      }
    }
  }
  cout << area << '\n';
}
