#include <bits/stdc++.h>
using namespace std;
const long long oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
void compress(vector<long long> &i2x, map<long long, long long> &x2i) {
  sort(begin(i2x), end(i2x));
  i2x.erase(unique(begin(i2x), end(i2x)), end(i2x));
  for (long long i = (0); i < (long long((i2x).size())); i++) x2i[i2x[i]] = i;
}
const long long N = 1010;
bool wallns[N][N], wallew[N][N], reach[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long m, n;
  cin >> m >> n;
  vector<long long> i2x = {-oo, oo}, j2y = {-oo, oo};
  vector<tuple<long long, long long, long long>> ns, ew;
  while (m--) {
    long long a, b, c;
    cin >> a >> b >> c;
    i2x.push_back(a), i2x.push_back(b), j2y.push_back(c);
    ns.push_back(make_tuple(a, b, c));
  }
  while (n--) {
    long long d, e, f;
    cin >> d >> e >> f;
    i2x.push_back(d), j2y.push_back(e), j2y.push_back(f);
    ew.push_back(make_tuple(d, e, f));
  }
  map<long long, long long> x2i, y2j;
  compress(i2x, x2i), compress(j2y, y2j);
  for (auto tpl : ns) {
    long long a, b, c;
    tie(a, b, c) = tpl;
    a = x2i[a], b = x2i[b], c = y2j[c];
    for (long long i = (a); i < (b); i++) wallns[i][c - 1] = 1;
  }
  for (auto tpl : ew) {
    long long d, e, f;
    tie(d, e, f) = tpl;
    d = x2i[d], e = y2j[e], f = y2j[f];
    for (long long j = (e); j < (f); j++) wallew[d - 1][j] = 1;
  }
  queue<pair<long long, long long>> q;
  for (long long i = (0); i < (long long((i2x).size()) - 1); i++)
    if (i2x[i] <= 0 && i2x[i + 1] >= 0) {
      for (long long j = (0); j < (long long((j2y).size()) - 1); j++)
        if (j2y[j] <= 0 && j2y[j + 1] >= 0) {
          q.emplace(i, j), reach[i][j] = 1;
        }
    }
  while (long long((q).size())) {
    long long i, j;
    tie(i, j) = q.front();
    q.pop();
    if (i > 0 && !wallew[i - 1][j] && !reach[i - 1][j]) {
      q.emplace(i - 1, j), reach[i - 1][j] = 1;
    }
    if (j > 0 && !wallns[i][j - 1] && !reach[i][j - 1]) {
      q.emplace(i, j - 1), reach[i][j - 1] = 1;
    }
    if (i + 2 < long long((i2x).size()) && !wallew[i][j] && !reach[i + 1][j]) {
      q.emplace(i + 1, j), reach[i + 1][j] = 1;
    }
    if (j + 2 < long long((j2y).size()) && !wallns[i][j] && !reach[i][j + 1]) {
      q.emplace(i, j + 1), reach[i][j + 1] = 1;
    }
  }
  long long res = 0;
  for (long long i = (0); i < (long long((i2x).size()) - 1); i++)
    for (long long j = (0); j < (long long((j2y).size()) - 1); j++)
      if (reach[i][j]) {
        if (i == 0 || j == 0 || i == long long((i2x).size()) - 2 ||
            j == long long((j2y).size()) - 2) {
          cout << "INF" << endl;
          return 0;
        }
        res += (i2x[i + 1] - i2x[i]) * (j2y[j + 1] - j2y[j]);
      }
  cout << res << endl;
}
