#include <bits/stdc++.h>
using namespace std;
vector<int> A;
vector<int> B;
vector<int> C;
vector<int> D;
vector<int> E;
vector<int> F;
vector<long long> xs;
vector<long long> ys;
int st[6001][6001];
bool isInf = false;
long long f(int p, int q) {
  stack<pair<long long, long long> > nex;
  long long ret = 0;
  nex.push(pair<long long, long long>(p, q));
  while (nex.size()) {
    p = nex.top().first;
    q = nex.top().second;
    nex.pop();
    if (st[p][q] & 16) {
      return 0;
    }
    st[p][q] |= 16;
    if (p == 0 || q == 0 || p == xs.size() || q == ys.size()) {
      isInf = true;
      return 0;
    }
    ret += (xs[p] - xs[p - 1]) * (ys[q] - ys[q - 1]);
    if (!(st[p][q] & 1)) {
      nex.push(pair<long long, long long>(p, q + 1));
    }
    if (!(st[p][q] & 2)) {
      nex.push(pair<long long, long long>(p + 1, q));
    }
    if (!(st[p][q] & 4)) {
      nex.push(pair<long long, long long>(p, q - 1));
    }
    if (!(st[p][q] & 8)) {
      nex.push(pair<long long, long long>(p - 1, q));
    }
  }
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    A.push_back(a);
    B.push_back(b);
    C.push_back(c);
    xs.push_back(a);
    xs.push_back(b);
    ys.push_back(c);
  }
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    D.push_back(a);
    E.push_back(b);
    F.push_back(c);
    xs.push_back(a);
    ys.push_back(b);
    ys.push_back(c);
  }
  sort(xs.begin(), xs.end());
  xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  sort(ys.begin(), ys.end());
  ys.resize(unique(ys.begin(), ys.end()) - ys.begin());
  for (int i = 0; i < N; i++) {
    int q = lower_bound(ys.begin(), ys.end(), C[i]) - ys.begin();
    int p = lower_bound(xs.begin(), xs.end(), min(A[i], B[i])) - xs.begin();
    while (xs[p] < max(A[i], B[i])) {
      st[p + 1][q] |= 1;
      st[p + 1][q + 1] |= 4;
      p++;
    }
  }
  for (int i = 0; i < M; i++) {
    int q = lower_bound(ys.begin(), ys.end(), min(E[i], F[i])) - ys.begin();
    int p = lower_bound(xs.begin(), xs.end(), D[i]) - xs.begin();
    while (ys[q] < max(E[i], F[i])) {
      st[p][q + 1] |= 2;
      st[p + 1][q + 1] |= 8;
      q++;
    }
  }
  int u = lower_bound(xs.begin(), xs.end(), 0) - xs.begin();
  int v = lower_bound(ys.begin(), ys.end(), 0) - ys.begin();
  long long r = f(u, v);
  if (isInf) {
    cout << "INF" << endl;
    return 0;
  }
  cout << r << endl;
  return 0;
}
