#include <bits/stdc++.h>
template <typename T>
bool mins(T& x, const T& y) {
  if (x > y) {
    x = y;
    return true;
  } else
    return false;
}
template <typename T>
bool maxs(T& x, const T& y) {
  if (x < y) {
    x = y;
    return true;
  } else
    return false;
}
const long long int INF = 1e18;
using namespace std;
void Main() {
  long long int n, M;
  cin >> n >> M;
  vector<long long int> A(n), B(n), C(n);
  for (long long int i = 0; i < (long long int)(n); i++)
    cin >> A[i] >> B[i] >> C[i];
  vector<long long int> D(M), E(M), F(M);
  for (long long int i = 0; i < (long long int)(M); i++)
    cin >> D[i] >> E[i] >> F[i];
  vector<long long int> xs;
  xs.push_back(-INF);
  xs.push_back(-1);
  xs.push_back(0);
  xs.push_back(1);
  xs.push_back(INF);
  for (long long int i = 0; i < (long long int)(n); i++) {
    for (int j = -1; j <= 1; j++) xs.push_back(C[i] + j);
  }
  for (long long int i = 0; i < (long long int)(M); i++) {
    for (int j = -1; j <= 1; j++) xs.push_back(E[i] + j);
    for (int j = -1; j <= 1; j++) xs.push_back(F[i] + j);
  }
  sort((xs).begin(), (xs).end());
  xs.erase(unique((xs).begin(), (xs).end()), xs.end());
  vector<long long int> ys;
  ys.push_back(-INF);
  ys.push_back(-1);
  ys.push_back(0);
  ys.push_back(1);
  ys.push_back(INF);
  for (long long int i = 0; i < (long long int)(n); i++) {
    for (int j = -1; j <= 1; j++) ys.push_back(A[i] + j);
    for (int j = -1; j <= 1; j++) ys.push_back(B[i] + j);
  }
  for (long long int i = 0; i < (long long int)(M); i++) {
    for (int j = -1; j <= 1; j++) ys.push_back(D[i] + j);
  }
  sort((ys).begin(), (ys).end());
  ys.erase(unique((ys).begin(), (ys).end()), ys.end());
  long long int H = ys.size(), W = xs.size();
  vector<long long int> a(n), b(n), c(n);
  vector<vector<long long int>> Z(H, vector<long long int>(W));
  for (long long int i = 0; i < (long long int)(n); i++) {
    a[i] = lower_bound((ys).begin(), (ys).end(), A[i]) - ys.begin();
    b[i] = lower_bound((ys).begin(), (ys).end(), B[i]) - ys.begin();
    c[i] = lower_bound((xs).begin(), (xs).end(), C[i]) - xs.begin();
    for (long long int j = a[i]; j < b[i]; j++) {
      Z[j][c[i]] |= 1 << 0;
      Z[j][c[i] - 1] |= 1 << 2;
    }
  }
  vector<long long int> d(M), e(M), f(M);
  for (long long int i = 0; i < (long long int)(M); i++) {
    d[i] = lower_bound((ys).begin(), (ys).end(), D[i]) - ys.begin();
    e[i] = lower_bound((xs).begin(), (xs).end(), E[i]) - xs.begin();
    f[i] = lower_bound((xs).begin(), (xs).end(), F[i]) - xs.begin();
    for (long long int j = e[i]; j < f[i]; j++) {
      Z[d[i]][j] |= 1 << 1;
      Z[d[i] - 1][j] |= 1 << 3;
    }
  }
  long long int sx = lower_bound((xs).begin(), (xs).end(), 0) - xs.begin();
  long long int sy = lower_bound((ys).begin(), (ys).end(), 0) - ys.begin();
  long long int gx = lower_bound((xs).begin(), (xs).end(), INF) - xs.begin();
  long long int gy = lower_bound((ys).begin(), (ys).end(), INF) - ys.begin();
  vector<vector<long long int>> dp(H, vector<long long int>(W, INF));
  queue<pair<long long int, long long int>> que;
  que.push(pair<long long int, long long int>(sx, sy));
  dp[sy][sx] = 0;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, -1, 0, 1};
  while (que.empty() == false) {
    pair<long long int, long long int> q = que.front();
    long long int x = q.first;
    long long int y = q.second;
    que.pop();
    for (long long int i = 0; i < (long long int)(4); i++) {
      long long int x2 = dx[i] + x;
      long long int y2 = dy[i] + y;
      if (x2 < 0 || W <= x2 || y2 < 0 || H <= y2) {
        continue;
      }
      if (dp[y2][x2] != INF) {
        continue;
      }
      if (Z[y][x] & (1 << i)) {
      } else {
        dp[y2][x2] = dp[y][x] + 1;
        que.push(pair<long long int, long long int>(x2, y2));
      }
    }
  }
  if (dp[gy][gx] != INF) {
    std::cout << "INF" << endl;
    ;
  } else {
    long long int res = 0;
    for (long long int y = 0; y < (long long int)(H); y++)
      for (long long int x = 0; x < (long long int)(W); x++) {
        if (dp[y][x] == INF) {
          continue;
        }
        long long int ddy = ys[y] - ys[y + 1];
        long long int ddx = xs[x] - xs[x + 1];
        res += ddx * ddy;
      }
    std::cout << res << endl;
    ;
  }
}
signed main() {
  Main();
  return 0;
}
