#include <bits/stdc++.h>
using namespace std;
struct Area {
  long long area;
  bool visited;
  bool cango[4];
  Area() {
    area = 0;
    visited = false;
    for (int i = (0); i < (int)(4); i++) cango[i] = true;
  }
};
int vx[4] = {1, -1, 0, 0};
int vy[4] = {0, 0, 1, -1};
Area field[2005][2005];
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<long long>> v, w;
  map<long long, int> zx, zy;
  zx[-1000000005] = 1;
  zx[0] = 1;
  zx[1000000005] = 1;
  zy[-1000000005] = 1;
  zy[0] = 1;
  zy[1000000005] = 1;
  for (int i = (0); i < (int)(N); i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    v.push_back({a, b, c});
    zx[a] = 1;
    zx[b] = 1;
    zy[c] = 1;
  }
  for (int i = (0); i < (int)(M); i++) {
    long long d, e, f;
    cin >> d >> e >> f;
    w.push_back({d, e, f});
    zx[d] = 1;
    zy[e] = 1;
    zy[f] = 1;
  }
  map<int, long long> rzx, rzy;
  int height = 0, width = 0;
  {
    for (__typeof((zx).begin()) it = (zx).begin(); it != (zx).end(); ++it) {
      rzx[height] = it->first;
      it->second = height++;
    }
  }
  {
    for (__typeof((zy).begin()) it = (zy).begin(); it != (zy).end(); ++it) {
      rzy[width] = it->first;
      it->second = width++;
    }
  }
  for (int i = (0); i < (int)(height - 1); i++) {
    for (int j = (0); j < (int)(width - 1); j++) {
      if (i == 0 || j == 0 || i == height - 2 || j == width - 2) {
        field[i][j].area = -1;
      } else {
        long long x = rzx[i];
        long long y = rzy[j];
        long long xx = rzx[i + 1];
        long long yy = rzy[j + 1];
        field[i][j].area = (xx - x) * (yy - y);
      }
    }
  }
  for (int i = (0); i < (int)(N); i++) {
    int x = zx[v[i][0]];
    int xx = zx[v[i][1]];
    int y = zy[v[i][2]];
    for (int j = (x); j < (int)(xx); j++) {
      field[j][y - 1].cango[2] = false;
      field[j][y].cango[3] = false;
    }
  }
  for (int i = (0); i < (int)(M); i++) {
    int x = zx[w[i][0]];
    int y = zy[w[i][1]];
    int yy = zy[w[i][2]];
    for (int j = (y); j < (int)(yy); j++) {
      field[x - 1][j].cango[0] = false;
      field[x][j].cango[1] = false;
    }
  }
  queue<pair<int, int>> que;
  int zero_x = zx[0], zero_y = zy[0];
  que.push(make_pair(zero_x - 1, zero_y - 1));
  que.push(make_pair(zero_x - 1, zero_y));
  que.push(make_pair(zero_x, zero_y - 1));
  que.push(make_pair(zero_x, zero_y));
  long long ret = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    if (field[p.first][p.second].visited) continue;
    field[p.first][p.second].visited = true;
    if (field[p.first][p.second].area < 0) {
      ret = -1;
      break;
    }
    ret += field[p.first][p.second].area;
    for (int k = (0); k < (int)(4); k++) {
      int nx = p.first + vx[k];
      int ny = p.second + vy[k];
      if (field[p.first][p.second].cango[k]) {
        if (!field[nx][ny].visited) {
          que.push(make_pair(nx, ny));
        }
      }
    }
  }
  if (ret < 0) {
    cout << "INF" << endl;
  } else {
    cout << ret << endl;
  }
  return 0;
}
