#include <bits/stdc++.h>
using namespace std;
struct Line {
  long long int A, B, C;
};
struct Info {
  Info() { x = y = 0; }
  Info(long long int arg_x, long long int arg_y) {
    x = arg_x;
    y = arg_y;
  }
  long long int x, y;
};
long long int N, M;
long long int diff_row[4] = {-1, 0, 0, 1}, diff_col[4] = {0, -1, 1, 0};
Line tate[1005], yoko[1005];
map<long long int, long long int> mapX, mapY;
short table[4 * 1005][4 * 1005];
int main() {
  scanf("%lld %lld", &N, &M);
  vector<long long int> X, Y;
  X.push_back(0);
  Y.push_back(0);
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld %lld", &tate[i].A, &tate[i].B, &tate[i].C);
    X.push_back(tate[i].A);
    X.push_back(tate[i].B);
    Y.push_back(tate[i].C);
  }
  for (int i = 0; i < M; i++) {
    scanf("%lld %lld %lld", &yoko[i].A, &yoko[i].B, &yoko[i].C);
    X.push_back(yoko[i].A);
    Y.push_back(yoko[i].B);
    Y.push_back(yoko[i].C);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  for (long long int i = 0; i < X.size(); i++) {
    mapX[X[i]] = i;
  }
  for (long long int i = 0; i < Y.size(); i++) {
    mapY[Y[i]] = i;
  }
  long long int H = X.size() * 2;
  long long int W = Y.size() * 2;
  for (int row = 0; row < H; row++) {
    for (int col = 0; col < W; col++) {
      table[row][col] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    long long int a = mapX[tate[i].A] * 2;
    long long int b = mapX[tate[i].B] * 2;
    long long int c = mapY[tate[i].C] * 2;
    for (long long int x = a; x <= b; x++) {
      table[x][c] = -1;
    }
  }
  for (int i = 0; i < M; i++) {
    long long int a = mapX[yoko[i].A] * 2;
    long long int b = mapY[yoko[i].B] * 2;
    long long int c = mapY[yoko[i].C] * 2;
    for (int y = b; y <= c; y++) {
      table[a][y] = -1;
    }
  }
  queue<Info> Q;
  long long int start_x = mapX[0] * 2;
  long long int start_y = mapY[0] * 2;
  table[start_x][start_y] = 1;
  Q.push(Info(start_x, start_y));
  Info info;
  while (!Q.empty()) {
    info = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      long long int adj_x = info.x + diff_row[i];
      long long int adj_y = info.y + diff_col[i];
      if (adj_x < 0 || adj_x >= H) continue;
      if (adj_y < 0 || adj_y >= W) continue;
      if (table[adj_x][adj_y] != 0) continue;
      table[adj_x][adj_y] = 1;
      Q.push(Info(adj_x, adj_y));
    }
  }
  long long int ans = 0;
  for (long long int row = 0; row < H; row++) {
    for (long long int col = 0; col < W; col++) {
      if (table[row][col] != 1) continue;
      if (row == 0 || row == H - 1 || col == 0 || col == W - 1) {
        printf("INF\n");
        return 0;
      }
      if (row % 2 == 0 || col % 2 == 0) continue;
      long long int tmp_x = X[row / 2 + 1] - X[row / 2];
      long long int tmp_y = Y[col / 2 + 1] - Y[col / 2];
      ans += tmp_x * tmp_y;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
