#include <bits/stdc++.h>
using namespace std;
struct Hline {
  int x, sy, ey;
};
struct Wline {
  int y, sx, ex;
};
int N, M, SY = -1, SX = -1;
vector<int> Y, X;
vector<Hline> H;
vector<Wline> W;
map<int, int> newY, newX;
long long area[4040][4040];
bool vis[4040][4040], cutY[4040][4040], cutX[4040][4040];
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
void DFS(int y, int x) {
  vis[y][x] = true;
  for (int i = 0; i < 4; i++) {
    int ny = y + dir[i][0], nx = x + dir[i][1];
    if (ny < 0 || nx < 0 || ny >= (int)Y.size() - 1 ||
        nx >= (int)X.size() - 1) {
      printf("INF");
      exit(0);
    }
    if (vis[ny][nx]) continue;
    DFS(ny, nx);
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= N; i++) {
    int sy, ey, x;
    scanf("%d %d %d", &sy, &ey, &x);
    H.push_back({x, sy, ey});
  }
  for (int i = 1; i <= M; i++) {
    int y, sx, ex;
    scanf("%d %d %d", &y, &sx, &ex);
    W.push_back({y, sx, ex});
  }
  for (int i = 0; i < H.size(); i++) {
    X.push_back(H[i].x);
    Y.push_back(H[i].sy);
    Y.push_back(H[i].ey);
  }
  for (int i = 0; i < W.size(); i++) {
    X.push_back(W[i].sx);
    X.push_back(W[i].ex);
    Y.push_back(W[i].y);
  }
  sort(Y.begin(), Y.end());
  sort(X.begin(), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  for (int i = 0; i < Y.size(); i++) newY[Y[i]] = i;
  for (int i = 0; i < X.size(); i++) newX[X[i]] = i;
  for (int i = 0; i < (int)Y.size() - 1; i++) {
    for (int j = 0; j < (int)X.size() - 1; j++) {
      area[i][j] = (long long)(Y[i + 1] - Y[i]) * (X[j + 1] - X[j]);
      if (Y[i] <= 0 && 0 < Y[i + 1] && X[j] <= 0 && 0 < X[j + 1])
        SY = i, SX = j;
    }
  }
  for (int i = 0; i < H.size(); i++) {
    int x = H[i].x, sy = H[i].sy, ey = H[i].ey;
    x = newX[x];
    sy = newY[sy];
    ey = newY[ey];
    for (int y = sy; y < ey; y++) cutX[y][x] = true;
  }
  for (int i = 0; i < W.size(); i++) {
    int y = W[i].y, sx = W[i].sx, ex = W[i].ex;
    y = newY[y];
    sx = newX[sx];
    ex = newX[ex];
    for (int x = sx; x < ex; x++) cutY[y][x] = true;
  }
  if (SY == -1 && SX == -1) return !printf("INF");
  while (Y.size() > 3000 || X.size() > 3000)
    ;
  DFS(SY, SX);
  long long res = 0;
  for (int i = 0; i < 4040; i++)
    for (int j = 0; j < 4040; j++)
      if (vis[i][j]) res += area[i][j];
  printf("%lld", res);
  return 0;
}
