#include <bits/stdc++.h>
using namespace std;
tuple<int, int, int> horizontalLines[1005], verticalLines[1005];
vector<int> interestingX, interestingY, uniqueX, uniqueY;
bool directions[3005][3005][4];
bool visited[3005][3005];
void dfs(int currX, int currY) {
  if (currX < 0 || currX >= (int)(uniqueX.size()) || currY < 0 ||
      currY >= (int)(uniqueY.size()))
    return;
  if (visited[currX][currY]) return;
  visited[currX][currY] = true;
  if (directions[currX][currY][0]) dfs(currX - 1, currY);
  if (directions[currX][currY][1]) dfs(currX + 1, currY);
  if (directions[currX][currY][2]) dfs(currX, currY - 1);
  if (directions[currX][currY][3]) dfs(currX, currY + 1);
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    int Ai, Bi, Ci;
    scanf("%d%d%d", &Ai, &Bi, &Ci);
    verticalLines[i] = make_tuple(Ai, Bi, Ci);
    interestingX.push_back(Ai);
    interestingX.push_back(Bi);
    interestingY.push_back(Ci);
  }
  for (int i = 1; i <= M; i++) {
    int Di, Ei, Fi;
    scanf("%d%d%d", &Di, &Ei, &Fi);
    horizontalLines[i] = make_tuple(Di, Ei, Fi);
    interestingX.push_back(Di);
    interestingY.push_back(Ei);
    interestingY.push_back(Fi);
  }
  interestingX.push_back(0);
  interestingY.push_back(0);
  sort(interestingX.begin(), interestingX.end());
  sort(interestingY.begin(), interestingY.end());
  uniqueX.push_back(INT_MIN);
  uniqueX.push_back(interestingX[0]);
  for (int i = 1; i < (int)(interestingX.size()); i++) {
    if (interestingX[i] != interestingX[i - 1])
      uniqueX.push_back(interestingX[i]);
  }
  uniqueY.push_back(INT_MIN);
  uniqueY.push_back(interestingY[0]);
  for (int i = 1; i < (int)(interestingY.size()); i++) {
    if (interestingY[i] != interestingY[i - 1])
      uniqueY.push_back(interestingY[i]);
  }
  for (int i = 0; i < 3005; i++) {
    for (int j = 0; j < 3005; j++) {
      for (int k = 0; k < 4; k++) directions[i][j][k] = true;
    }
  }
  for (int i = 1; i <= N; i++) {
    int Ai = get<0>(verticalLines[i]), Bi = get<1>(verticalLines[i]),
        Ci = get<2>(verticalLines[i]);
    int reducedAi =
        lower_bound(uniqueX.begin(), uniqueX.end(), Ai) - uniqueX.begin();
    int reducedBi =
        lower_bound(uniqueX.begin(), uniqueX.end(), Bi) - uniqueX.begin();
    int reducedCi =
        lower_bound(uniqueY.begin(), uniqueY.end(), Ci) - uniqueY.begin();
    for (int j = reducedAi; j < reducedBi; j++) {
      directions[j][reducedCi][2] = false;
      directions[j][reducedCi - 1][3] = false;
    }
  }
  for (int i = 1; i <= M; i++) {
    int Di = get<0>(horizontalLines[i]), Ei = get<1>(horizontalLines[i]),
        Fi = get<2>(horizontalLines[i]);
    int reducedDi =
        lower_bound(uniqueX.begin(), uniqueX.end(), Di) - uniqueX.begin();
    int reducedEi =
        lower_bound(uniqueY.begin(), uniqueY.end(), Ei) - uniqueY.begin();
    int reducedFi =
        lower_bound(uniqueY.begin(), uniqueY.end(), Fi) - uniqueY.begin();
    for (int j = reducedEi; j < reducedFi; j++) {
      directions[reducedDi][j][0] = false;
      directions[reducedDi - 1][j][1] = false;
    }
  }
  vector<int>::iterator itr1 = lower_bound(uniqueX.begin(), uniqueX.end(), 0);
  vector<int>::iterator itr2 = lower_bound(uniqueY.begin(), uniqueY.end(), 0);
  dfs(itr1 - uniqueX.begin(), itr2 - uniqueY.begin());
  if (visited[0][0]) {
    printf("INF");
    return 0;
  }
  long long ans = 0;
  for (int i = 0; i < 3005; i++) {
    for (int j = 0; j < 3005; j++) {
      if (visited[i][j]) {
        if (i >= (int)uniqueX.size() - 1 || j >= (int)uniqueY.size() - 1) {
          printf("INF\n");
          return 0;
        }
        ans += (long long)(uniqueX[i + 1] - uniqueX[i]) *
               (uniqueY[j + 1] - uniqueY[j]);
      }
    }
  }
  printf("%lld", ans);
}
