#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
const int maxn = 200009;
const int MOD = 1e9 + 7;
int A[1111], B[1111], C[1111], D[1111], E[1111], F[1111];
bool vis[3333][3333];
bool dir[3333][3333][4];
int main() {
  FPEN FPEN2;
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> X, Y;
  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i] >> C[i];
    X.push_back(A[i]);
    X.push_back(B[i]);
    Y.push_back(C[i]);
  }
  for (int i = 0; i < M; ++i) {
    cin >> D[i] >> E[i] >> F[i];
    X.push_back(D[i]);
    Y.push_back(E[i]);
    Y.push_back(F[i]);
  }
  X.push_back(MOD), Y.push_back(MOD), X.push_back(-MOD), Y.push_back(-MOD), X.push_back(0), Y.push_back(0);
  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 (int i = 0; i < N; ++i) {
    A[i] = lower_bound(X.begin(), X.end(), A[i]) - X.begin();
    B[i] = lower_bound(X.begin(), X.end(), B[i]) - X.begin();
    C[i] = lower_bound(Y.begin(), Y.end(), C[i]) - Y.begin();
    for (int j = A[i]; j < B[i]; ++j) {
      dir[j][C[i]][0] = 1;
      dir[j][C[i] - 1][1] = 1;
    }
  }
  for (int i = 0; i < M; ++i) {
    D[i] = lower_bound(X.begin(), X.end(), D[i]) - X.begin();
    E[i] = lower_bound(Y.begin(), Y.end(), E[i]) - Y.begin();
    F[i] = lower_bound(Y.begin(), Y.end(), F[i]) - Y.begin();
    for (int j = E[i]; j < F[i]; ++j) {
      dir[D[i]][j][2] = 1;
      dir[D[i] - 1][j][3] = 1;
    }
  }
  vector<pair<int, int>> que;
  long long ans = 0;
  que.emplace_back(lower_bound(X.begin(), X.end(), 0) - X.begin(), lower_bound(Y.begin(), Y.end(), 0) - Y.begin());
  for (int i = 0; i < que.size(); ++i) {
    int x = que[i].first, y = que[i].second;
    if (x == 0 || x == X.size() - 1 || y == 0 || y == Y.size() - 1) {
      cout << "INF";
      return 0;
    }
    ans += 1ll * (X[x + 1] - X[x]) * (Y[y + 1] - Y[y]);
    vis[x][y] = 1;
    if (!dir[x][y][0] && !vis[x][y - 1]) {
      vis[x][y - 1] = 1;
      que.emplace_back(x, y - 1);
    }
    if (!dir[x][y][1] && !vis[x][y + 1]) {
      vis[x][y + 1] = 1;
      que.emplace_back(x, y + 1);
    }
    if (!dir[x][y][2] && !vis[x - 1][y]) {
      vis[x - 1][y] = 1;
      que.emplace_back(x - 1, y);
    }
    if (!dir[x][y][3] && !vis[x + 1][y]) {
      vis[x + 1][y] = 1;
      que.emplace_back(x + 1, y);
    }
  }
  cout << ans << '\n';
  return 0;
}
// <-:0 ->:1 ^:2 v:3