#include <bits/stdc++.h>
using namespace std;
int n, m;
int mup[3010][3010];
int mdown[3010][3010];
int mleft[3010][3010];
int mright[3010][3010];
int vis[3010][3010];
long long ans = 0;
pair<int, int> temp;
int tempx, tempy;
int newx, newy;
pair<int, int> dir[4] = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
bool flag = 0;
int a[1010], b[1010], c[1010];
int d[1010], e[1010], f[1010];
vector<int> xs;
int xsize, ysize;
vector<int> ys;
queue<pair<int, int> > qu;
int main() {
  scanf("%d%d", &n, &m);
  xs.push_back(-(int)(1e9 + 7));
  xs.push_back((int)(1e9 + 7));
  ys.push_back(-(int)(1e9 + 7));
  ys.push_back((int)(1e9 + 7));
  xs.push_back(0);
  ys.push_back(0);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    xs.push_back(a[i]);
    xs.push_back(b[i]);
    ys.push_back(c[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &d[i], &e[i], &f[i]);
    xs.push_back(d[i]);
    ys.push_back(e[i]);
    ys.push_back(f[i]);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  ys.resize(unique(ys.begin(), ys.end()) - ys.begin());
  for (int i = 0; i < n; i++) {
    int xx = lower_bound(ys.begin(), ys.end(), c[i]) - ys.begin();
    int yy1 = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
    int yy2 = lower_bound(xs.begin(), xs.end(), b[i]) - xs.begin();
    for (int j = yy1; j < yy2; j++) {
      mleft[xx][j] = 1;
      mright[xx - 1][j] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    int yy = lower_bound(xs.begin(), xs.end(), d[i]) - xs.begin();
    int xx1 = lower_bound(ys.begin(), ys.end(), e[i]) - ys.begin();
    int xx2 = lower_bound(ys.begin(), ys.end(), f[i]) - ys.begin();
    for (int j = xx1; j < xx2; j++) {
      mup[j][yy] = 1;
      mdown[j][yy - 1] = 1;
    }
  }
  int x = lower_bound(xs.begin(), xs.end(), 0) - xs.begin();
  int y = lower_bound(ys.begin(), ys.end(), 0) - ys.begin();
  qu.push(pair<int, int>{x, y});
  xsize = xs.size();
  ysize = ys.size();
  while (!qu.empty()) {
    temp = qu.front();
    qu.pop();
    tempx = temp.first;
    tempy = temp.second;
    if (vis[tempx][tempy]) continue;
    ans += (long long)(xs[tempx + 1] - xs[tempx]) *
           (long long)(ys[tempy + 1] - ys[tempy]);
    vis[tempx][tempy] = 1;
    if (tempx <= 0 || tempy <= 0) {
      flag = 1;
      break;
    }
    if (tempx >= xsize - 1 || tempy >= ysize - 1) {
      flag = 1;
      break;
    }
    for (int i = 0; i < 4; i++) {
      if (i == 0 && mup[tempx][tempy]) continue;
      if (i == 1 && mdown[tempx][tempy]) continue;
      if (i == 2 && mleft[tempx][tempy]) continue;
      if (i == 3 && mright[tempx][tempy]) continue;
      newx = tempx + dir[i].first;
      newy = tempy + dir[i].second;
      qu.push(pair<int, int>(newx, newy));
    }
  }
  if (flag)
    printf("INF");
  else
    printf("%lld", ans);
}
