#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % (long long)(1E9 + 7);
  if (c >= 0) return c;
  return c + (long long)(1E9 + 7);
}
long long inf = (long long)1E16;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long &pos, long long val) { pos = max(pos, val); }
void Min(long long &pos, long long val) { pos = min(pos, val); }
void Add(long long &pos, long long val) { pos = mod(pos + val); }
long double EPS = 1E-9;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long dx[4] = {0, 1, -1, 0};
long long dy[4] = {1, 0, 0, -1};
void no() {
  cout << "INF"
       << "\n";
  exit(0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n], b[n], c[n];
  long long d[m], e[m], f[m];
  for (long long i = 0; i <= n - 1; i++) cin >> a[i] >> b[i] >> c[i];
  for (long long i = 0; i <= m - 1; i++) cin >> d[i] >> e[i] >> f[i];
  vector<long long> x, y;
  x.push_back(-inf);
  x.push_back(inf);
  y.push_back(-inf);
  y.push_back(inf);
  x.push_back(0);
  y.push_back(0);
  for (long long i = 0; i <= n - 1; i++) {
    x.push_back(a[i]);
    x.push_back(b[i]);
    y.push_back(c[i]);
  }
  for (long long i = 0; i <= m - 1; i++) {
    x.push_back(d[i]);
    y.push_back(e[i]);
    y.push_back(f[i]);
  }
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  sort(y.begin(), y.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  for (long long i = 0; i <= n - 1; i++) {
    a[i] = (lower_bound(x.begin(), x.end(), a[i]) - x.begin());
    b[i] = (lower_bound(x.begin(), x.end(), b[i]) - x.begin());
    c[i] = (lower_bound(y.begin(), y.end(), c[i]) - y.begin());
  }
  for (long long i = 0; i <= m - 1; i++) {
    d[i] = (lower_bound(x.begin(), x.end(), d[i]) - x.begin());
    e[i] = (lower_bound(y.begin(), y.end(), e[i]) - y.begin());
    f[i] = (lower_bound(y.begin(), y.end(), f[i]) - y.begin());
  }
  long long xs = x.size();
  long long ys = y.size();
  vector<pair<long long, long long> > ty[ys];
  vector<pair<long long, long long> > tx[xs];
  for (long long i = 0; i <= n - 1; i++) {
    ty[c[i]].push_back({a[i], b[i]});
  }
  for (long long i = 0; i <= m - 1; i++) {
    tx[d[i]].push_back({e[i], f[i]});
  }
  long long mp[xs * 2 + 1][ys * 2 + 1];
  memset(mp, 0, sizeof(mp));
  for (long long i = 0; i <= n - 1; i++) {
    long long C = c[i] * 2 + 1;
    long long A = a[i] * 2 + 1;
    long long B = b[i] * 2 + 1;
    for (long long j = A; j <= B; j++) {
      mp[j][C] = -1;
    }
  }
  for (long long i = 0; i <= m - 1; i++) {
    long long D = d[i] * 2 + 1;
    long long E = e[i] * 2 + 1;
    long long F = f[i] * 2 + 1;
    for (long long j = E; j <= F; j++) {
      mp[D][j] = -1;
    }
  }
  long long stax = (lower_bound(x.begin(), x.end(), 0) - x.begin()) * 2;
  long long stay = (lower_bound(y.begin(), y.end(), 0) - y.begin()) * 2;
  queue<pair<long long, long long> > q;
  q.push({stax, stay});
  mp[stax][stay] = 1;
  while (!q.empty()) {
    pair<long long, long long> pos = q.front();
    q.pop();
    long long posx = pos.first;
    long long posy = pos.second;
    for (long long z = 0; z <= 3; z++) {
      long long newx = posx + dx[z];
      long long newy = posy + dy[z];
      if (0 <= newx && newx <= 2 * xs) {
        if (0 <= newy && newy <= 2 * ys) {
          if (mp[newx][newy] == 0) {
            mp[newx][newy] = 1;
            q.push({newx, newy});
          }
        }
      }
    }
  }
  for (long long i = 0; i <= 2 * xs; i++) {
    if (mp[i][0] == 1) no();
    if (mp[i][2 * ys] == 1) no();
  }
  for (long long i = 0; i <= 2 * ys; i++) {
    if (mp[0][i] == 1) no();
    if (mp[2 * xs][i] == 1) no();
  }
  long long ans = 0;
  for (long long i = 0; i <= xs - 2; i++) {
    for (long long j = 0; j <= ys - 2; j++) {
      long long ax = x[i];
      long long bx = x[i + 1];
      long long ay = y[j];
      long long by = y[j + 1];
      if (mp[i * 2 + 2][j * 2 + 2] == 1) {
        ans += (by - ay) * (bx - ax);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
