#include <bits/stdc++.h>
using namespace std;
using LP = pair<long long, long long>;
using P = pair<int, int>;
const long long mod = 1e9 + 7;
struct L {
  int a, b, c;
  L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c){};
};
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mpX, mpY;
  mpX[0] = 0;
  mpY[0] = 0;
  vector<L> lh, lv;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    mpX[a] = 0;
    mpX[b] = 0;
    mpY[c] = 0;
    lh.emplace_back(a, b, c);
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> c >> a >> b;
    mpY[a] = 0;
    mpY[b] = 0;
    mpX[c] = 0;
    lv.emplace_back(a, b, c);
  }
  vector<int> xs, ys;
  for (auto& p : mpX) {
    p.second = xs.size();
    xs.push_back(p.first);
  }
  for (auto& p : mpY) {
    p.second = ys.size();
    ys.push_back(p.first);
  }
  int h = 2 * xs.size();
  int w = 2 * ys.size();
  vector<vector<int>> d(h, vector<int>(w, 0));
  for (int i = 0; i < n; i++) {
    int a = mpX[lh[i].a] * 2;
    int b = mpX[lh[i].b] * 2;
    int c = mpY[lh[i].c] * 2;
    for (int x = a; x < b + 1; x++) d[x][c] = -1;
  }
  for (int i = 0; i < m; i++) {
    int a = mpY[lv[i].a] * 2;
    int b = mpY[lv[i].b] * 2;
    int c = mpX[lv[i].c] * 2;
    for (int y = a; y < b + 1; y++) d[c][y] = -1;
  }
  queue<P> q;
  int sx = mpX[0] * 2;
  int sy = mpY[0] * 2;
  q.emplace(sx, sy);
  d[sx][sy] = 1;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int v = 0; v < 4; v++) {
      int nx = x + dx[v];
      int ny = y + dy[v];
      if (nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
      if (d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx, ny);
    }
  }
  long long ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (d[i][j] != 1) continue;
      if (i == 0 or i == h - 1 or j == 0 or j == w - 1) {
        cout << "INF" << endl;
        return 0;
      }
      if (i % 2 == 0 or j % 2 == 0) continue;
      long long tmp = (xs[i / 2 + 1] - xs[i / 2]) * (ys[j / 2 + 1] - ys[j / 2]);
      ans += tmp;
    }
  cout << ans << endl;
  return 0;
}
