#include <bits/stdc++.h>
using namespace std;
constexpr int kDirections = 4;
constexpr int kDx[kDirections] = {-1, +1, 0, 0};
constexpr int kDy[kDirections] = {0, 0, -1, +1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> vertical, horizontal;
  vector<int> cmp_x = {0}, cmp_y = {0};
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a *= 2;
    b *= 2;
    c *= 2;
    cmp_x.push_back(a);
    cmp_x.push_back(b);
    cmp_y.push_back(c);
    cmp_x.push_back(a + 1);
    cmp_x.push_back(b + 1);
    cmp_x.push_back(a - 1);
    cmp_x.push_back(b - 1);
    cmp_y.push_back(c - 1);
    cmp_y.push_back(c + 1);
    vertical.emplace_back(a, b, c);
  }
  for (int i = 0; i < m; ++i) {
    int d, e, f;
    cin >> d >> e >> f;
    d *= 2;
    e *= 2;
    f *= 2;
    cmp_x.push_back(d);
    cmp_y.push_back(e);
    cmp_y.push_back(f);
    cmp_x.push_back(d - 1);
    cmp_x.push_back(d + 1);
    cmp_y.push_back(e + 1);
    cmp_y.push_back(f + 1);
    cmp_y.push_back(e - 1);
    cmp_y.push_back(f - 1);
    horizontal.emplace_back(d, e, f);
  }
  sort(cmp_x.begin(), cmp_x.end());
  cmp_x.erase(unique(cmp_x.begin(), cmp_x.end()), cmp_x.end());
  sort(cmp_y.begin(), cmp_y.end());
  cmp_y.erase(unique(cmp_y.begin(), cmp_y.end()), cmp_y.end());
  n = static_cast<int>(cmp_x.size());
  m = static_cast<int>(cmp_y.size());
  vector<vector<char>> blocked(n, vector<char>(m));
  for (auto item : vertical) {
    int a, b, c;
    tie(a, b, c) = item;
    a = lower_bound(cmp_x.begin(), cmp_x.end(), a) - cmp_x.begin();
    b = lower_bound(cmp_x.begin(), cmp_x.end(), b) - cmp_x.begin();
    c = lower_bound(cmp_y.begin(), cmp_y.end(), c) - cmp_y.begin();
    for (int i = a; i <= b; ++i) blocked[i][c] = true;
  }
  for (auto item : horizontal) {
    int d, e, f;
    tie(d, e, f) = item;
    d = lower_bound(cmp_x.begin(), cmp_x.end(), d) - cmp_x.begin();
    e = lower_bound(cmp_y.begin(), cmp_y.end(), e) - cmp_y.begin();
    f = lower_bound(cmp_y.begin(), cmp_y.end(), f) - cmp_y.begin();
    for (int i = e; i <= f; ++i) blocked[d][i] = true;
  }
  int x = lower_bound(cmp_x.begin(), cmp_x.end(), 0) - cmp_x.begin();
  int y = lower_bound(cmp_y.begin(), cmp_y.end(), 0) - cmp_y.begin();
  queue<pair<int, int>> q;
  vector<vector<char>> used(n, vector<char>(m));
  q.push({x, y});
  used[x][y] = 1;
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    for (int i = 0; i < kDirections; ++i) {
      int nx = x + kDx[i];
      int ny = y + kDy[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) {
        cout << "INF\n";
        return 0;
      }
      if (used[nx][ny] || blocked[nx][ny]) continue;
      used[nx][ny] = 1;
      q.push({nx, ny});
    }
  }
  long long result = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (used[i][j] && ((cmp_x[i] % 2 && cmp_y[j] % 2))) {
        long long dx = cmp_x[i + 1] - cmp_x[i - 1];
        long long dy = cmp_y[j + 1] - cmp_y[j - 1];
        result += dx * dy;
      }
    }
  }
  cout << result / 4 << '\n';
}
