#include <bits/stdc++.h>
using namespace std;
long long INF = LLONG_MAX;
int const mxn = 4444;
int n, m;
int a[mxn], b[mxn], c[mxn], d[mxn], e[mxn], f[mxn];
bool vis[mxn][mxn], up[mxn][mxn], dw[mxn][mxn], le[mxn][mxn], ri[mxn][mxn];
int const dx[] = {-1, 0, 1, 0};
int const dy[] = {0, -1, 0, 1};
vector<int> xx = {-1000000007, 1000000007}, yy = {-1000000007, 1000000007};
void bfs(int x, int y) {
  queue<pair<int, int> > q;
  q.emplace(x, y);
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    if (vis[x][y]) continue;
    vis[x][y] = 1;
    for (int i = 0; i < 4; i++) {
      int X = x + dx[i];
      int Y = y + dy[i];
      if (X < 0 || X >= (int)xx.size() - 1) continue;
      if (Y < 0 || Y >= (int)yy.size() - 1) continue;
      if (vis[X][Y]) continue;
      if (i == 0 && le[X][Y]) continue;
      if (i == 1 && dw[X][Y]) continue;
      if (i == 2 && ri[X][Y]) continue;
      if (i == 3 && up[X][Y]) continue;
      q.emplace(X, Y);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    xx.push_back(a[i]);
    xx.push_back(b[i]);
    yy.push_back(c[i]);
  }
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    xx.push_back(d[i]);
    yy.push_back(e[i]);
    yy.push_back(f[i]);
  }
  sort((xx).begin(), (xx).end());
  xx.erase(unique((xx).begin(), (xx).end()), xx.end());
  sort((yy).begin(), (yy).end());
  yy.erase(unique((yy).begin(), (yy).end()), yy.end());
  for (int i = 0; i < n; i++) {
    int x1 = lower_bound((xx).begin(), (xx).end(), a[i]) - xx.begin();
    int x2 = lower_bound((xx).begin(), (xx).end(), b[i]) - xx.begin();
    int y = lower_bound((yy).begin(), (yy).end(), c[i]) - yy.begin();
    for (int j = x1; j < x2; j++) {
      up[j][y] = 1;
      dw[j][y - 1] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    int x = lower_bound((xx).begin(), (xx).end(), d[i]) - xx.begin();
    int y1 = lower_bound((yy).begin(), (yy).end(), e[i]) - yy.begin();
    int y2 = lower_bound((yy).begin(), (yy).end(), f[i]) - yy.begin();
    for (int j = y1; j < y2; j++) {
      ri[x][j] = 1;
      le[x - 1][j] = 1;
    }
  }
  int x = lower_bound((xx).begin(), (xx).end(), 0) - xx.begin();
  int y = lower_bound((yy).begin(), (yy).end(), 0) - yy.begin();
  bfs(x, y);
  if (vis[0][0] || vis[xx.size() - 1][yy.size() - 1]) {
    cout << "INF" << endl;
    return 0;
  }
  long long ans = 0LL;
  for (int i = 0; i < (int)xx.size() - 1; i++)
    for (int j = 0; j < (int)yy.size() - 1; j++)
      if (vis[i][j]) ans += long long(xx[i + 1] - xx[i]) * (yy[j + 1] - yy[j]);
  cout << ans << endl;
}
