#include <bits/stdc++.h>
using namespace std;
map<long long int, int> mappax, mappay;
set<pair<int, int> > grafo[3000][3000];
set<long long int> x, y;
long long int invmapx[3000], invmapy[3000];
int N, M;
long long int a[3000], b[3000], c[3000];
bool reached[3000][3000];
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
    x.insert(a[i]);
    x.insert(b[i]);
    y.insert(c[i]);
  }
  for (int i = 0; i < M; i++) {
    cin >> a[i + N] >> b[i + N] >> c[i + N];
    x.insert(a[i + N]);
    y.insert(b[i + N]);
    y.insert(c[i + N]);
  }
  x.insert(1000000001);
  x.insert(-1000000001);
  y.insert(1000000001);
  y.insert(-1000000001);
  int cardx = 0;
  for (set<long long int>::iterator it = x.begin(); it != x.end(); it++) {
    invmapx[cardx] = *it;
    mappax[*it] = cardx;
    cardx++;
  }
  int cardy = 0;
  for (set<long long int>::iterator it = y.begin(); it != y.end(); it++) {
    invmapy[cardy] = *it;
    mappay[*it] = cardy;
    cardy++;
  }
  for (int i = 0; i < N; i++) {
    int X1 = mappax[a[i]];
    int X2 = mappax[b[i]];
    int Y = mappay[c[i]];
    for (int j = X1; j < X2; j++) {
      grafo[Y - 1][j].insert(make_pair(Y, j));
      grafo[Y][j].insert(make_pair(Y - 1, j));
    }
  }
  for (int i = N; i < N + M; i++) {
    int X = mappax[a[i]];
    int Y1 = mappax[b[i]];
    int Y2 = mappay[c[i]];
    for (int j = Y1; j < Y2; j++) {
      grafo[j][X - 1].insert(make_pair(j, X));
      grafo[j][X].insert(make_pair(j, X - 1));
    }
  }
  int x0 = 0;
  while (invmapx[x0 + 1] < 0) x0++;
  int y0 = 0;
  while (invmapy[y0 + 1] < 0) y0++;
  queue<pair<int, int> > Q;
  Q.push(make_pair(y0, x0));
  reached[y0][x0] = true;
  while (!Q.empty()) {
    pair<int, int> d = Q.front();
    Q.pop();
    if (d.first != 0 &&
        grafo[d.first][d.second].find(make_pair(d.first - 1, d.second)) ==
            grafo[d.first][d.second].end() &&
        !reached[d.first - 1][d.second]) {
      reached[d.first - 1][d.second] = true;
      Q.push(make_pair(d.first - 1, d.second));
    }
    if (d.second != cardx - 1 &&
        grafo[d.first][d.second].find(make_pair(d.first, d.second + 1)) ==
            grafo[d.first][d.second].end() &&
        !reached[d.first][d.second + 1]) {
      reached[d.first][d.second + 1] = true;
      Q.push(make_pair(d.first, d.second + 1));
    }
    if (d.second != 0 &&
        grafo[d.first][d.second].find(make_pair(d.first, d.second - 1)) ==
            grafo[d.first][d.second].end() &&
        !reached[d.first][d.second - 1]) {
      reached[d.first][d.second - 1] = true;
      Q.push(make_pair(d.first, d.second - 1));
    }
    if (d.first != cardy - 1 &&
        grafo[d.first][d.second].find(make_pair(d.first + 1, d.second)) ==
            grafo[d.first][d.second].end() &&
        !reached[d.first + 1][d.second]) {
      reached[d.first + 1][d.second] = true;
      Q.push(make_pair(d.first + 1, d.second));
    }
  }
  for (int i = 0; i < cardx; i++) {
    if (reached[0][i] || reached[cardy - 1][i]) {
      cout << "INF\n";
      return 0;
    }
  }
  for (int i = 0; i < cardy; i++) {
    if (reached[i][0] || reached[i][cardx - 1]) {
      cout << "INF\n";
      return 0;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < cardy; i++)
    for (int j = 0; j < cardx; j++)
      if (reached[i][j])
        ans =
            ans + (invmapx[j + 1] - invmapx[j]) * (invmapy[i + 1] - invmapy[i]);
  cout << ans << endl;
  return 0;
}
