#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
struct debug {
  template <class T>
  debug& operator<<(const T&) {
    return *this;
  }
};
using ll = long long;
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
const int mxN = 4005;
const int inf = 1e9 + 5;
int seen[mxN][mxN], no_up[mxN][mxN], no_down[mxN][mxN], no_left[mxN][mxN],
    no_right[mxN][mxN];
int a[mxN], b[mxN], c[mxN], d[mxN], e[mxN], f[mxN];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
vector<int> xs{-inf, inf}, ys{-inf, inf};
void bfs(int x, int y) {
  vector<pair<int, int>> q{{x, y}};
  seen[x][y] = 1;
  for (int i = 0; i < int(q.size()); i++) {
    x = q[i].first, y = q[i].second;
    for (int k = 0; k < int(4); k++) {
      if (k == 0 && no_left[x][y]) continue;
      if (k == 1 && no_down[x][y]) continue;
      if (k == 2 && no_up[x][y]) continue;
      if (k == 3 && no_right[x][y]) continue;
      int nx = x + dx[k];
      int ny = y + dy[k];
      if (nx < 0 || ny < 0 || nx >= (int)xs.size() || ny >= (int)ys.size())
        continue;
      if (seen[nx][ny]) continue;
      seen[nx][ny] = 1;
      q.emplace_back(nx, ny);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    xs.push_back(a[i]);
    xs.push_back(b[i]);
    ys.push_back(c[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    ys.push_back(e[i]);
    ys.push_back(f[i]);
    xs.push_back(d[i]);
  }
  sort(xs.begin(), xs.end());
  xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  sort(ys.begin(), ys.end());
  ys.resize(unique(ys.begin(), ys.end()) - ys.begin());
  int x = (lower_bound(xs.begin(), xs.end(), 0) - xs.begin());
  int y = (lower_bound(ys.begin(), ys.end(), 0) - ys.begin());
  x--, y--;
  debug() << "[ "
          << "x"
             ": "
          << (x) << " ] "
          << "[ "
          << "y"
             ": "
          << (y) << " ] ";
  for (int i = 0; i < int(n); i++) {
    int aa = (lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin());
    int bb = (lower_bound(xs.begin(), xs.end(), b[i]) - xs.begin());
    int cc = (lower_bound(ys.begin(), ys.end(), c[i]) - ys.begin());
    for (int j = aa; j < bb; j++) {
      no_up[j][cc - 1] = 1;
      no_down[j][cc] = 1;
    }
  }
  for (int i = 0; i < int(m); i++) {
    int dd = (lower_bound(xs.begin(), xs.end(), d[i]) - xs.begin());
    int ee = (lower_bound(ys.begin(), ys.end(), e[i]) - ys.begin());
    int ff = (lower_bound(ys.begin(), ys.end(), f[i]) - ys.begin());
    for (int j = ee; j < ff; j++) {
      no_right[dd - 1][j] = 1;
      no_left[dd][j] = 1;
    }
  }
  bfs(x, y);
  n = xs.size();
  m = ys.size();
  if (seen[0][0] || seen[n - 1][m - 1]) {
    cout << "INF\n";
    exit(0);
  }
  ll ans = 0;
  for (int i = 0; i < int(n - 1); i++)
    for (int j = 0; j < int(m - 1); j++) {
      if (seen[i][j]) {
        ans += 1LL * (xs[i + 1] - xs[i]) * (ys[i + 1] - ys[i]);
      }
    }
  cout << ans << endl;
}
