#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> x;
  vector<long long> y;
  vector<vector<long long>> abc(N);
  vector<vector<long long>> def(M);
  bool ok = true;
  for (long long i = 0; i < N; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    abc.at(i) = {a, b, c};
    if (c == 0 && (a <= 0 && 0 <= b)) {
      ok = false;
    }
    x.push_back(a - 1);
    x.push_back(a);
    x.push_back(b);
    x.push_back(b + 1);
    y.push_back(c - 1);
    y.push_back(c);
    y.push_back(c + 1);
  }
  for (long long i = 0; i < M; ++i) {
    long long d, e, f;
    cin >> d >> e >> f;
    if (d == 0 && (e <= 0 && 0 <= f)) {
      ok = false;
    }
    def.at(i) = {d, e, f};
    x.push_back(d - 1);
    x.push_back(d);
    x.push_back(d + 1);
    y.push_back(e - 1);
    y.push_back(e);
    y.push_back(f);
    y.push_back(f + 1);
  }
  if (!ok) {
    cout << 0 << endl;
    return 0;
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  vector<vector<long long>> fixed_abc(N), fixed_def(M);
  for (long long i = 0; i < N; ++i) {
    vector<long long> check = abc.at(i);
    fixed_abc.at(i) = {
        lower_bound(x.begin(), x.end(), check.at(0)) - x.begin(),
        lower_bound(x.begin(), x.end(), check.at(1)) - x.begin(),
        lower_bound(y.begin(), y.end(), check.at(2)) - y.begin()};
  }
  for (long long i = 0; i < M; ++i) {
    vector<long long> check = def.at(i);
    fixed_def.at(i) = {
        lower_bound(x.begin(), x.end(), check.at(0)) - x.begin(),
        lower_bound(y.begin(), y.end(), check.at(1)) - y.begin(),
        lower_bound(y.begin(), y.end(), check.at(2)) - y.begin()};
  }
  vector<vector<long long>> field(y.size() + 2,
                                  vector<long long>(x.size() + 2, -1));
  for (long long i = 1; i <= y.size(); ++i) {
    for (long long j = 1; j <= x.size(); ++j) {
      field.at(i).at(j) = 0;
    }
  }
  for (long long i = 0; i < N; ++i) {
    vector<long long> check = fixed_abc.at(i);
    for (long long x_len = check.at(0); x_len <= check.at(1); ++x_len) {
      field.at(check.at(2)).at(x_len) = 1;
    }
  }
  for (long long i = 0; i < M; ++i) {
    vector<long long> check = fixed_def.at(i);
    for (long long y_len = check.at(1); y_len <= check.at(2); ++y_len) {
      field.at(y_len).at(check.at(0)) = 1;
    }
  }
  pair<long long, long long> start = {
      lower_bound(x.begin(), x.end(), 0) - x.begin() + 1,
      lower_bound(y.begin(), y.end(), 0) - y.begin() + 1};
  queue<pair<long long, long long>> q;
  q.push(start);
  vector<vector<long long>> move = {{0, 1},  {1, 0}, {0, -1},
                                    {-1, 0}, {1, 1}, {-1, -1}};
  while (!q.empty()) {
    pair<long long, long long> now = q.front();
    q.pop();
    for (long long i = 0; i < 6; ++i) {
      pair<long long, long long> next = {now.first + move.at(i).at(0),
                                         now.second + move.at(i).at(1)};
      if (field.at(next.second).at(next.first) == -1) {
        cout << "INF"
             << "\n";
        return 0;
      }
      if (field.at(next.second).at(next.first) == 0) {
        field.at(next.second).at(next.first) = 2;
        q.push({next.first, next.second});
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < y.size() - 1; ++i) {
    for (long long j = 0; j < x.size() - 1; ++j) {
      if (field.at(i + 1).at(j + 1) == 2) {
        long long x_wid = x.at(j) - x.at(j - 1), y_wid = y.at(i) - y.at(i - 1);
        if (field.at(i + 2).at(j + 1) == 1) {
          y_wid = y.at(i + 1) - y.at(i - 1);
        }
        if (field.at(i + 1).at(j + 2) == 1) {
          x_wid = x.at(j + 1) - x.at(j - 1);
        }
        ans += (x_wid * y_wid);
      }
    }
  }
  cout << ans << "\n";
}
