#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <typename T>
int compress(vector<T> org, map<T, int> &zip, vector<T> &unzip) {
  sort(org.begin(), org.end());
  org.erase(unique(org.begin(), org.end()), org.end());
  int i = 0;
  for (auto &oi : org) {
    zip[oi] = i;
    unzip.push_back(oi);
    i++;
  }
  return i;
}
struct line {
  ll a, b, c;
};
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  line tate[n], yoko[m];
  vector<ll> org, unzip;
  for (auto &ti : tate) {
    cin >> ti.a >> ti.b >> ti.c;
    org.push_back(ti.a);
    org.push_back(ti.b);
    org.push_back(ti.c);
  }
  for (auto &yi : yoko) {
    cin >> yi.c >> yi.a >> yi.b;
    org.push_back(yi.a);
    org.push_back(yi.b);
    org.push_back(yi.c);
  }
  map<ll, int> zip;
  int k = compress(org, zip, unzip);
  vector<P> tatel[k];
  vector<P> yokol[k];
  for (auto &ti : tate) {
    tatel[zip[ti.c]].push_back(P{zip[ti.a], zip[ti.b]});
  }
  for (auto &yi : yoko) {
    yokol[zip[yi.c]].push_back(P{zip[yi.a], zip[yi.b]});
  }
  ll grid[2 * k + 1][2 * k + 1];
  fill(grid[0], grid[2 * k + 1], 0);
  for (int i = 0; i < k; i++) {
    sort(tatel[i].begin(), tatel[i].end());
    int j = 0;
    for (auto &ti : tatel[i]) {
      for (j = max(j, 2 * ti.first + 1); j <= 2 * ti.second + 1; j++) {
        grid[2 * i + 1][j] = -1;
      }
    }
  }
  for (int j = 0; j < k; j++) {
    sort(yokol[j].begin(), yokol[j].end());
    int i = 0;
    for (auto &ti : yokol[j]) {
      for (i = max(i, 2 * ti.first + 1); i <= 2 * ti.second + 1; i++) {
        grid[i][2 * j + 1] = -1;
      }
    }
  }
  for (int i = 0; i < 2 * k + 1; i++) {
    for (int j = 0; j < 2 * k + 1; j++) {
      if (i == 0 || j == 0 || i == 2 * k || j == 2 * k) {
        grid[i][j] = -2;
      } else if (i % 2 == 0 && j % 2 == 0) {
        grid[i][j] = (unzip[i / 2] - unzip[i / 2 - 1]) *
                     (unzip[j / 2] - unzip[j / 2 - 1]);
      }
    }
  }
  int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
  queue<P> q;
  q.push({2 * zip[0] + 1, 2 * zip[0] + 1});
  grid[2 * zip[0] + 1][2 * zip[0] + 1] = -1;
  ll ans = 0;
  while (!q.empty()) {
    P f = q.front();
    q.pop();
    xmin = min(xmin, f.first);
    ymin = min(ymin, f.second);
    xmax = max(xmax, f.first);
    ymax = max(ymax, f.second);
    for (int x = f.first - 1; x <= f.first + 1; x++) {
      for (int y = f.second - 1; y <= f.second + 1; y++) {
        if (x != f.first && y != f.second) continue;
        if (grid[x][y] == -1) continue;
        if (grid[x][y] == -2) {
          cout << "INF" << '\n';
          return 0;
        }
        ans += grid[x][y];
        grid[x][y] = -1;
        q.push({x, y});
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
