#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 2e9;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
vector<T> compress(vector<T> A) {
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  return A;
}
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
long long n, m;
void solve() {
  cin >> n >> m;
  vector<long long> xs = {-INF, INF}, ys = {-INF, INF};
  auto add = [&](long long x, long long y) {
    xs.push_back(x);
    ys.push_back(y);
  };
  vector<long long> a(n), b(n), c(n), d(m), e(m), f(m);
  for (long long i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    add(a[i], c[i]);
    add(b[i], c[i]);
  }
  for (long long i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    add(d[i], e[i]);
    add(d[i], f[i]);
  }
  xs = compress(xs);
  ys = compress(ys);
  long long xsz = (long long)xs.size(), ysz = (long long)ys.size();
  auto find_x = [&](long long x) -> long long {
    return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
  };
  auto find_y = [&](long long y) -> long long {
    return upper_bound(ys.begin(), ys.end(), y) - ys.begin() - 1;
  };
  static bitset<3100> above[3100], left[3100];
  for (long long i = 0; i < n; i++) {
    a[i] = find_x(a[i]);
    b[i] = find_x(b[i]);
    c[i] = find_y(c[i]);
    for (long long x = a[i]; x < b[i]; ++x) {
      left[x][c[i]] = 1;
    }
  }
  for (long long i = 0; i < m; i++) {
    d[i] = find_x(d[i]);
    e[i] = find_y(e[i]);
    f[i] = find_y(f[i]);
    for (long long y = e[i]; y < f[i]; ++y) {
      above[d[i]][y] = 1;
    }
  }
  long long cowx = find_x(0), cowy = find_y(0);
  vector<vector<long long>> dist(xsz, vector<long long>(ysz, INF));
  dist[cowx][cowy] = 0;
  queue<pair<long long, long long>> que;
  que.push(pair<long long, long long>{cowx, cowy});
  auto check = [&](long long x, long long y) -> bool {
    return (0 <= x && x < xsz && 0 <= y && y < ysz);
  };
  while (!que.empty()) {
    pair<long long, long long> p = que.front();
    que.pop();
    long long x = p.first, y = p.second;
    if (check(x, y - 1) && !left[x][y] &&
        chmin(dist[x][y - 1], dist[x][y] + 1)) {
      que.push(pair<long long, long long>{x, y - 1});
    }
    if (check(x - 1, y) && !above[x][y] &&
        chmin(dist[x - 1][y], dist[x][y] + 1)) {
      que.push(pair<long long, long long>{x - 1, y});
    }
    if (check(x, y + 1) && !left[x][y + 1] &&
        chmin(dist[x][y + 1], dist[x][y] + 1)) {
      que.push(pair<long long, long long>{x, y + 1});
    }
    if (check(x + 1, y) && !above[x + 1][y] &&
        chmin(dist[x + 1][y], dist[x][y] + 1)) {
      que.push(pair<long long, long long>{x + 1, y});
    }
  }
  long long ans = 0;
  for (long long i = 0; i < xsz - 1; i++) {
    for (long long j = 0; j < ysz - 1; j++) {
      long long dx = xs[i + 1] - xs[i], dy = ys[i + 1] - ys[i];
      if (dist[i][j] < INF) {
        if (i == 0 || j == 0 || i == xsz - 2 || j == ysz - 2) {
          cout << "INF" << endl;
          return;
        }
        ans += dx * dy;
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
