#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10;
int n, m;
int A[N], B[N], C[N], D[N], E[N], F[N];
long long ans;
vector<int> xx, yy;
int id(vector<int>& vc, int x) {
  return lower_bound(vc.begin(), vc.end(), x) - vc.begin();
}
int dx[]{0, 0, -1, 1};
int dy[]{-1, 1, 0, 0};
int die[N][N][4];
queue<pair<int, int> > q;
int vis[N][N];
int main() {
  scanf("%d%d", &n, &m);
  xx.push_back(0);
  yy.push_back(0);
  xx.push_back(-INF);
  xx.push_back(INF);
  yy.push_back(-INF);
  yy.push_back(INF);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &A[i], &B[i], &C[i]);
    xx.push_back(A[i]);
    xx.push_back(B[i]);
    yy.push_back(C[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &D[i], &E[i], &F[i]);
    yy.push_back(E[i]);
    yy.push_back(F[i]);
    xx.push_back(D[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());
  for (int i = 1; i <= n; i++) {
    A[i] = id(xx, A[i]);
    B[i] = id(xx, B[i]);
    C[i] = id(yy, C[i]);
    for (int j = A[i]; j < B[i]; j++) {
      die[j][C[i]][0] = 1;
      die[j][C[i] - 1][1] = 1;
    }
  }
  for (int i = 1; i <= m; i++) {
    D[i] = id(xx, D[i]);
    E[i] = id(yy, E[i]);
    F[i] = id(yy, F[i]);
    for (int j = E[i]; j < F[i]; j++) {
      die[D[i]][j][2] = 1;
      die[D[i] - 1][j][3] = 1;
    }
  }
  q.push(pair<int, int>(id(xx, 0), id(yy, 0)));
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      if (die[x][y][i]) continue;
      int nx = x + dx[i], ny = y + dy[i];
      if (nx == 0 || nx == (int)xx.size() - 1 || ny == 0 ||
          ny == (int)yy.size() - 1) {
        puts("INF");
        return 0;
      }
      if (vis[nx][ny]) continue;
      vis[nx][ny] = 1;
      ans += 1ll * (xx[nx + 1] - xx[nx]) * (yy[ny + 1] - yy[ny]);
      q.push(pair<int, int>(nx, ny));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
