#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll mod = 1000000007;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
struct L {
  int a, b, c;
  L(int a, int b, int c) : a(a), b(b), c(c) {}
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<L> lh;
  vector<L> lv;
  map<int, int> mpx;
  map<int, int> mpy;
  mpx[0] = 0;
  mpy[0] = 0;
  for (int i = (0); i < (n); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    lh.emplace_back(a, b, c);
    mpx[a] = 0;
    mpx[b] = 0;
    mpy[c] = 0;
  }
  for (int i = (0); i < (m); ++i) {
    int d, e, f;
    cin >> d >> e >> f;
    lv.emplace_back(e, f, d);
    mpx[d] = 0;
    mpy[e] = 0;
    mpy[f] = 0;
  }
  vector<int> xs;
  vector<int> ys;
  for (auto& m : mpx) {
    m.second = xs.size();
    xs.push_back(m.first);
  }
  for (auto& m : mpy) {
    m.second = ys.size();
    ys.push_back(m.first);
  }
  int nx = xs.size() * 2;
  int ny = ys.size() * 2;
  vector<vector<int>> g(nx, vector<int>(ny));
  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; x++) g[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; y++) g[c][y] = -1;
  }
  queue<P> q;
  P start = P(mpx[0] * 2, mpy[0] * 2);
  g[start.first][start.second] = 1;
  q.push(start);
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    int x = now.first;
    int y = now.second;
    for (int i = (0); i < (4); ++i) {
      int ix = x + dx[i];
      int iy = y + dy[i];
      if (ix < 0 || ix >= nx || iy < 0 || iy >= nx) continue;
      if (g[ix][iy] != 0) continue;
      g[ix][iy] = 1;
      q.emplace(ix, iy);
    }
  }
  ll ans = 0;
  for (int i = (0); i < (nx); ++i)
    for (int j = (0); j < (ny); ++j) {
      if (g[i][j] != 1) continue;
      if (i == 0 || i == nx - 1 || j == 0 || j == ny - 1) {
        cout << "INF" << endl;
        return 0;
      }
      if (i % 2 == 0 || j % 2 == 0) continue;
      int dx = xs[i / 2 + 1] - xs[i / 2];
      int dy = ys[j / 2 + 1] - ys[j / 2];
      ans += dx * dy;
    }
  cout << ans << endl;
  return 0;
}
