#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int grid[5000][5000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N), C(N), D(M), E(M), F(M);
  set<int> sx, sy;
  sx.insert(0);
  sy.insert(0);
  for (int i = 0; i < (N); ++i) {
    cin >> A[i] >> B[i] >> C[i];
    sx.insert(A[i]);
    sx.insert(B[i]);
    sy.insert(C[i]);
  }
  for (int i = 0; i < (M); ++i) {
    cin >> D[i] >> E[i] >> F[i];
    sx.insert(D[i]);
    sy.insert(E[i]);
    sy.insert(F[i]);
  }
  map<int, int> x2i, y2i;
  vector<int> i2x, i2y;
  for (int x : sx) {
    x2i[x] = i2x.size();
    i2x.push_back(x);
  }
  for (int y : sy) {
    y2i[y] = i2y.size();
    i2y.push_back(y);
  }
  for (int i = 0; i < (N); ++i) {
    int ix1 = x2i[A[i]] * 2;
    int ix2 = x2i[B[i]] * 2;
    if (ix2 < ix1) swap(ix1, ix2);
    int iy = y2i[C[i]] * 2;
    for (int ix = ix1; ix <= ix2; ++ix) {
      grid[iy][ix] = -1;
    }
  }
  for (int i = 0; i < (M); ++i) {
    int ix = x2i[D[i]] * 2;
    int iy1 = y2i[E[i]] * 2;
    int iy2 = y2i[F[i]] * 2;
    if (iy2 < iy1) swap(iy1, iy2);
    for (int iy = iy1; iy <= iy2; ++iy) {
      grid[iy][ix] = -1;
    }
  }
  int dx[] = {0, -1, 1, 0};
  int dy[] = {-1, 0, 0, 1};
  long long ans = 0;
  queue<pair<int, int>> q;
  q.emplace(x2i[0] * 2, y2i[0] * 2);
  grid[y2i[0] * 2][x2i[0] * 2] = 1;
  while (!q.empty()) {
    pair<int, int> curr = q.front();
    q.pop();
    for (int i = 0; i < (4); ++i) {
      int x = curr.first + dx[i];
      int y = curr.second + dy[i];
      if (x < 0 || 2 * i2x.size() <= x || y < 0 || 2 * i2y.size() <= y) {
        cout << "INF" << endl;
        return 0;
      }
      if (grid[y][x] == 0) {
        grid[y][x] = 1;
        q.emplace(x, y);
        if (y % 2 && x % 2) {
          int iy = y / 2;
          int ix = x / 2;
          ans += (i2x[ix + 1] - i2x[ix]) * (i2y[iy + 1] - i2y[iy]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
