#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr long long mod = 1e9 + 7;
constexpr long long inf = 3e18;
long long N, M;
vector<long long> xx, yy;
long long A[1005], B[1005], C[1005];
long long D[1005], E[1005], F[1005];
bool b[2005][2005], ng[2005][2005][4];
void idx(vector<long long> &v, long long &x) {
  x = lower_bound(v.begin(), v.end(), x) - v.begin();
}
signed main() {
  cin >> N >> M;
  xx.push_back(-inf);
  xx.push_back(inf);
  xx.push_back(0);
  yy.push_back(-inf);
  yy.push_back(inf);
  yy.push_back(0);
  for (long long i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i];
    xx.push_back(A[i]);
    xx.push_back(B[i]);
    yy.push_back(C[i]);
  }
  for (long long i = 0; i < M; i++) {
    cin >> D[i] >> E[i] >> F[i];
    xx.push_back(D[i]);
    yy.push_back(E[i]);
    yy.push_back(F[i]);
  }
  sort(xx.begin(), xx.end());
  xx.erase(unique(xx.begin(), xx.end()), xx.end());
  sort(yy.begin(), yy.end());
  yy.erase(unique(yy.begin(), yy.end()), yy.end());
  long long dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
  for (long long i = 0; i < N; i++) {
    idx(xx, A[i]);
    idx(xx, B[i]);
    idx(yy, C[i]);
    for (long long j = A[i]; j < B[i]; j++) {
      ng[j][C[i]][2] = true;
      ng[j][C[i] - 1][0] = true;
    }
  }
  for (long long i = 0; i < M; i++) {
    idx(xx, D[i]);
    idx(yy, E[i]);
    idx(yy, F[i]);
    for (long long j = E[i]; j < F[i]; j++) {
      ng[D[i]][j][3] = true;
      ng[D[i] - 1][j][1] = true;
    }
  }
  queue<pair<long long, long long> > que;
  long long x = lower_bound(xx.begin(), xx.end(), 0ll) - xx.begin();
  long long y = lower_bound(yy.begin(), yy.end(), 0ll) - yy.begin();
  long long ans = 0;
  que.push({x, y});
  while (!que.empty()) {
    pair<long long, long long> p = que.front();
    que.pop();
    for (long long i = 0; i < 4; i++) {
      if (ng[p.first][p.second][i]) continue;
      long long nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx == 0 || nx == xx.size() - 1 || ny == 0 || ny == yy.size() - 1) {
        cout << "INF" << endl;
        return 0;
      }
      if (!b[nx][ny]) {
        ans += (xx[nx + 1] - xx[nx]) * (yy[ny + 1] - yy[ny]);
        b[nx][ny] = true;
        que.push({nx, ny});
      }
    }
  }
  cout << ans << endl;
}
