#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;

const int INF = 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[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main() {
  int n, m; cin >> n >> m;
  map<int, int> xmp, ymp;
  xmp[0] = 0, ymp[0] = 0;

  vector<L> lh, lv;
  rep(i,n) {
    int a, b, c;
    cin >> a >> b >> c;
    xmp[a] = 0;
    xmp[b] = 0;
    ymp[c] = 0;
    lv.emplace_back(a,b,c);
  }
  rep(i,m) {
    int a, b, c;
    cin >> c >> a >> b;
    ymp[a] = 0;
    ymp[b] = 0;
    xmp[c] = 0;
    lh.emplace_back(a,b,c);
  }

  vec xs, ys;
  for (auto& p: xmp) {
    p.second = xs.size();
    xs.push_back(p.first);
  }
  for (auto& p: ymp) {
    p.second = ys.size();
    ys.push_back(p.first);
  }

  int h = xs.size()*2;
  int w = ys.size()*2;

  vector<vec> d(h, vec(w));
  rep(i,n) {
    int a = xmp[lv[i].a]*2;
    int b = xmp[lv[i].b]*2;
    int c = ymp[lv[i].c]*2;
    for (int x = a; x <= b; x++) d[x][c] = -1;
  }
  rep(i,m) {
    int a = ymp[lh[i].a]*2;
    int b = ymp[lh[i].b]*2;
    int c = xmp[lh[i].c]*2;
    for (int y = a; y <= b; y++) d[c][y] = -1;
  }

  // bfs
  queue<P> q;
  int sx = xmp[0]*2, sy = ymp[0]*2;
  d[sx][sy] = 1;
  q.emplace(sx,sy);
  while (!q.empty()) {
    P p = q.front(); q.pop();
    int x = p.first, y = p.second;
    rep(v,4) {
      int nx = x+dx[v], ny = y+dy[v];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && d[nx][ny] == 0) {
        q.emplace(nx, ny);
        d[nx][ny] = 1;
      }
    }
  }

  ll ans = 0;
  rep(x,h) rep(y,w) {
    if (d[x][y] != 1) continue;
    if (x == 0 || x == h-1 || y == 0 || y == w-1) {
      cout << "INF" << endl;
      return 0;
    }
    if (x%2 == 0 || y%2 == 0) continue;
    ll ex = xs[x/2+1] - xs[x/2];
    ll ey = ys[y/2+1] - ys[y/2];
    ans += ex*ey;
  }
  cout << ans << endl;
  return 0;
}
