#include <bits/stdc++.h>
using namespace std;
bool _wh[1000][1000];
bool _wv[1000][1000];
vector<long long> xb;
vector<long long> yb;
bool isconnected(pair<int, int> x1, pair<int, int> x2) {
  if (x1.second < x2.first) return false;
  if (x1.first > x2.second) return false;
  return true;
}
void addline(vector<pair<int, int>> &lines, pair<int, int> l) {
  for (int i = 0; i < lines.size(); i++) {
    while (i < lines.size() && isconnected(lines[i], l)) {
      l = make_pair(min(l.first, lines[i].first),
                    max(l.second, lines[i].second));
      lines.erase(lines.begin() + i);
    }
  }
  lines.push_back(l);
}
bool _movemap[1000][1000];
bool checkmove(int i, int j, int n, int m) {
  if (i < 0 || i >= m - 1 || j < 0 || j >= n - 1) return true;
  if (_movemap[i][j]) return false;
  _movemap[i][j] = true;
  if (!_wh[i][j] && checkmove(i, j - 1, n, m)) return true;
  if (!_wh[i][j + 1] && checkmove(i, j + 1, n, m)) return true;
  if (!_wv[i][j] && checkmove(i - 1, j, n, m)) return true;
  if (!_wv[i + 1][j] && checkmove(i + 1, j, n, m)) return true;
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  map<int, vector<pair<int, int>>> hlines;
  map<int, vector<pair<int, int>>> vlines;
  for (int y = 0; y < n; y++) {
    int a, b, c;
    cin >> a >> b >> c;
    addline(hlines[c], make_pair(a, b));
    yb.push_back(c);
  }
  for (int x = 0; x < m; x++) {
    int d, e, f;
    cin >> d >> e >> f;
    addline(vlines[d], make_pair(e, f));
    xb.push_back(d);
  }
  sort(xb.begin(), xb.end());
  sort(yb.begin(), yb.end());
  vector<vector<bool> *> wallsh;
  for (int j = 0; j < n; j++) {
    vector<pair<int, int>> *lines = &hlines[yb[j]];
    for (int i = 0; i < m - 1; i++) _wh[i][j] = false;
    for (int k = 0; k < lines->size(); k++) {
      int i = 0;
      while (i < m && xb[i] < (*lines)[k].first) i++;
      while (i + 1 < m && (*lines)[k].second >= xb[i + 1]) {
        _wh[i][j] = true;
        i++;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    vector<pair<int, int>> *lines = &vlines[xb[i]];
    for (int j = 0; j < n - 1; j++) _wv[i][j] = false;
    for (int k = 0; k < lines->size(); k++) {
      int j = 0;
      while (j < n && yb[j] < (*lines)[k].first) j++;
      while (j + 1 < n && (*lines)[k].second >= yb[j + 1]) {
        _wv[i][j] = true;
        j++;
      }
    }
  }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) _movemap[i][j] = false;
  int xi = 0;
  int yi = 0;
  while (xi < m && xb[xi] < 0) xi++;
  while (yi < m && yb[yi] < 0) yi++;
  if (xi == m || yi == n) {
    cout << "INF";
  } else if (checkmove(xi, yi, n, m)) {
    cout << "INF";
  } else {
    long long ans = 0;
    for (int i = 0; i < m - 1; i++) {
      for (int j = 0; j < n - 1; j++) {
        if (_movemap[i][j]) {
          ans += (xb[i + 1] - xb[i]) * (yb[j + 1] - yb[j]);
        }
      }
    }
    cout << ans;
  }
}
