#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > muki = {
    pair<long long, long long>(1, 0), pair<long long, long long>(0, 1),
    pair<long long, long long>(-1, 0), pair<long long, long long>(0, -1)};
long long INF = 1e18;
map<long long, long long> m, mm;
vector<long long> gm, gmm;
long long N, K;
pair<long long, long long> A[1005];
long long C[1005];
pair<long long, long long> E[1005];
long long D[1005];
long long V[6005][6005];
stack<pair<long long, long long> > now;
long long ans;
int main() {
  cin >> N >> K;
  m[0] = 0;
  mm[0] = 0;
  for (int i = 0; i < N; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    m[a] = 0;
    m[b] = 0;
    mm[c] = 0;
    A[i] = pair<long long, long long>(a, b);
    C[i] = c;
  }
  for (int i = 0; i < K; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    mm[b] = 0;
    mm[c] = 0;
    m[a] = 0;
    D[i] = a;
    E[i] = pair<long long, long long>(b, c);
  }
  int ii = 0;
  for (auto& p : m) {
    p.second = 2 * ii + 1;
    ii++;
    gm.push_back(p.first);
  }
  int jj = 0;
  for (auto& p : mm) {
    p.second = 2 * jj + 1;
    jj++;
    gmm.push_back(p.first);
  }
  for (int i = 0; i < N; i++) {
    long long n = m[A[i].first];
    long long nn = m[A[i].second];
    long long nnn = mm[C[i]];
    for (long long j = n; j <= nn; j++) {
      V[j][nnn] = -1;
    }
  }
  for (int i = 0; i < N; i++) {
    long long n = mm[E[i].first];
    long long nn = mm[E[i].second];
    long long nnn = m[D[i]];
    for (long long j = n; j <= nn; j++) {
      V[nnn][j] = -1;
    }
  }
  now.push(pair<long long, long long>(m[0], mm[0]));
  V[m[0]][mm[0]] = 1;
  while (!now.empty()) {
    pair<long long, long long> s = now.top();
    now.pop();
    for (auto v : muki) {
      if (s.first + v.first >= 0 && s.first + v.first <= 2 * ii &&
          s.second + v.second >= 0 && s.second + v.second <= 2 * jj) {
        if (V[s.first + v.first][s.second + v.second] == 0) {
          now.push(pair<long long, long long>(s.first + v.first,
                                              s.second + v.second));
          V[s.first + v.first][s.second + v.second] = 1;
        }
      }
    }
  }
  for (int i = 0; i <= ii; i++) {
    for (int j = 0; j <= jj; j++) {
      if (V[2 * i][2 * j] == 1) {
        if (i == 0 || j == 0 || i == ii || j == jj) {
          cout << "INF" << endl;
          return 0;
        } else {
          ans += (gm[i] - gm[i - 1]) * (gmm[j] - gmm[j - 1]);
        }
      }
    }
  }
  cout << ans << endl;
}
