#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
  for (int i = 0; i < (n); ++i) cin >> a[i] >> b[i] >> c[i];
  for (int i = 0; i < (m); ++i) cin >> d[i] >> e[i] >> f[i];
  vector<int> xs;
  xs.push_back(0);
  for (int x : a) xs.push_back(x);
  for (int x : b) xs.push_back(x);
  for (int x : d) xs.push_back(x);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  map<int, int> xm;
  for (int i = 0; i < (xs.size()); ++i) xm[xs[i]] = i;
  vector<int> ys;
  ys.push_back(0);
  for (int y : c) ys.push_back(y);
  for (int y : e) ys.push_back(y);
  for (int y : f) ys.push_back(y);
  sort(ys.begin(), ys.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  map<int, int> ym;
  for (int i = 0; i < (ys.size()); ++i) ym[ys[i]] = i;
  vector<vector<bool>> visited(xs.size() * 2,
                               vector<bool>(ys.size() * 2, false));
  vector<int> xd(xs.size() * 2, 0);
  for (int i = 0; i < (xs.size() - 1); ++i) xd[i * 2 + 1] = xs[i + 1] - xs[i];
  vector<int> yd(ys.size() * 2, 0);
  for (int i = 0; i < (ys.size() - 1); ++i) yd[i * 2 + 1] = ys[i + 1] - ys[i];
  for (int i = 0; i < (n); ++i) {
    int y = ym[c[i]] * 2;
    for (int x = xm[a[i]] * 2; x < xm[b[i]] * 2; x++) visited[x][y] = true;
  }
  for (int i = 0; i < (m); ++i) {
    int x = xm[d[i]] * 2;
    for (int y = ym[e[i]] * 2; y < ym[f[i]] * 2; y++) visited[x][y] = true;
  }
  queue<P> q;
  q.emplace(xm[0] * 2, ym[0] * 2);
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  ll ans = 0;
  while (!q.empty()) {
    auto p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    if (x < 0 || x >= xs.size() * 2 || y < 0 || y >= ys.size() * 2) {
      cout << "INF" << endl;
      return 0;
    }
    if (visited[x][y]) continue;
    visited[x][y] = true;
    ans += xd[x] * yd[y];
    for (int i = 0; i < (4); ++i) q.emplace(x + dx[i], y + dy[i]);
  }
  cout << ans << endl;
}
