#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, int>> ver, hor;
  vector<int> xs, ys;
  xs.push_back(-1.1e9);
  xs.push_back(0);
  xs.push_back(1.1e9);
  ys.push_back(-1.1e9);
  ys.push_back(0);
  ys.push_back(1.1e9);
  for (int i = (0); i < (n); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    ver.emplace_back(make_pair(a, b), c);
    ys.push_back(a);
    ys.push_back(b);
    xs.push_back(c);
  }
  for (int i = (0); i < (m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    hor.emplace_back(make_pair(b, c), a);
    xs.push_back(b);
    xs.push_back(c);
    ys.push_back(a);
  }
  auto xpos = [&](int x) -> int {
    return lower_bound(begin(xs), end(xs), x) - xs.begin();
  };
  auto ypos = [&](int y) -> int {
    return lower_bound(begin(ys), end(ys), y) - ys.begin();
  };
  sort(begin(xs), end(xs));
  sort(begin(ys), end(ys));
  xs.resize(unique(begin(xs), end(xs)) - xs.begin());
  ys.resize(unique(begin(ys), end(ys)) - ys.begin());
  n = (int)(ys).size();
  m = (int)(xs).size();
  vector<vector<int>> mat(n, vector<int>(m));
  int di[4] = {0, -1, 0, 1};
  int dj[4] = {1, 0, -1, 0};
  for (int i = (0); i < ((int)(ver).size()); ++i) {
    auto [y1, y2] = ver[i].first;
    int x = ver[i].second;
    y1 = ypos(y1);
    y2 = ypos(y2);
    x = xpos(x);
    for (int i = (y1); i < (y2); ++i) {
      mat[i][x] |= 1 << 2;
      mat[i][x - 1] |= 1 << 0;
    }
  }
  for (int i = (0); i < ((int)(hor).size()); ++i) {
    auto [x1, x2] = hor[i].first;
    int y = hor[i].second;
    x1 = xpos(x1);
    x2 = xpos(x2);
    y = ypos(y);
    for (int i = (x1); i < (x2); ++i) {
      mat[y][i] |= 1 << 1;
      mat[y - 1][i] |= 1 << 3;
    }
  }
  queue<pair<int, int>> q;
  vector<bitset<2123>> vis(n);
  int x0 = xpos(0), y0 = ypos(0);
  q.emplace(y0, x0);
  q.emplace(y0 - 1, x0);
  q.emplace(y0, x0 - 1);
  q.emplace(y0 - 1, x0 - 1);
  vis[y0][x0] = 1;
  vis[y0 - 1][x0] = 1;
  vis[y0][x0 - 1] = 1;
  vis[y0 - 1][x0 - 1] = 1;
  while (not q.empty()) {
    auto [i, j] = q.front();
    q.pop();
    for (int k = (0); k < (4); ++k) {
      if (mat[i][j] & (1 << k)) continue;
      int ni = i + di[k], nj = j + dj[k];
      if (not((ni) >= 0 and (ni) < n and (nj) >= 0 and (nj) < m)) continue;
      if (vis[ni][nj]) continue;
      vis[ni][nj] = 1;
      q.emplace(ni, nj);
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (vis[i][0] or vis[i][m - 1]) {
      cout << "INF\n";
      return 0;
    }
  }
  for (int i = (0); i < (m); ++i) {
    if (vis[0][i] or vis[n - 1][i]) {
      cout << "INF\n";
      return 0;
    }
  }
  long long ans = 0;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j)
      if (vis[i][j]) {
        ans += long long(xs[j + 1] - xs[j]) * long long(ys[i + 1] - ys[i]);
      }
  cout << ans << '\n';
}
