#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;

struct L {
  int a, b, c;
  L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<L> ln(n), lm(m);
  map<int, int> mpx, mpy;
  mpx[0] = 0, mpy[0] = 0;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    ln[i] = L(a, b, c);
    mpx[a] = 0, mpx[b] = 0, mpy[c] = 0;
  }
  rep(i, m) {
    int a, b, c;
    cin >> c >> a >> b;
    lm[i] = L(a, b, c);
    mpy[a] = 0, mpy[b] = 0, mpx[c] = 0;
  }
  vector<int> xs, ys;
  for (auto &it : mpx) {
    it.second = xs.size();
    xs.push_back(it.first);
  }
  for (auto &it : mpy) {
    it.second = ys.size();
    ys.push_back(it.first);
  }
  int w = xs.size() * 2;
  int h = ys.size() * 2;
  vector<vector<int>> board(h, vector<int>(w));
  for (auto l : ln) {
    for (int i = mpx[l.a] * 2; i <= mpx[l.b] * 2; i++)
      board[mpy[l.c] * 2][i] = -1;
  }
  for (auto l : lm) {
    for (int i = mpy[l.a] * 2; i <= mpy[l.b] * 2; i++)
      board[i][mpx[l.c] * 2] = -1;
  }
  queue<pair<int, int>> bfs;
  int x = mpx[0] * 2, y = mpy[0] * 2;
  board[y][x] = 1;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, 1, 0, -1};
  bfs.push(make_pair(x, y));
  bool inf = false;
  while (!bfs.empty()) {
    x = bfs.front().first;
    y = bfs.front().second;
    bfs.pop();
    if (x <= 0 || w - 1 <= x || y <= 0 || h - 1 <= y) {
      inf = true;
      break;
    }
    rep(i, 4) {
      int xx = x + dx[i], yy = y + dy[i];
      if (board[yy][xx] != 0) continue;
      board[yy][xx] = 1;
      bfs.push(make_pair(xx, yy));
    }
  }
  if (inf) {
    cout << "INF" << endl;
    return 0;
  }
  ll sum = 0;
  for (int j = 1; j < h; j += 2)
    for (int i = 1; i < w; i += 2)
      if (board[j][i] == 1)
        sum += (ll)(xs[(i + 1) / 2] - xs[(i - 1) / 2]) * (ll)(ys[(j + 1) / 2] - ys[(j - 1) / 2]);
  cout << sum << endl;
  return 0;
}
