// 2020-06-24 22:53:17
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

struct Line {
  int a, b, c;
  Line(int a_, int b_, int c_) : a(a_), b(b_), c(c_) {}
};

void answer() {
  int n, m;
  cin >> n >> m;
  vector<Line> vs, hs; // x1, x2, y / y1, y2, x
  map<int, int> mapX, mapY;
  mapX[0] = 0;
  mapY[0] = 0;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c; // x1, x2, y
    vs.emplace_back(Line(a, b, c));
    mapX[a] = mapX[b] = mapY[c] = 0;
  }
  rep(i, m) {
    int a, b, c;
    cin >> c >> a >> b; // x, y1, y2
    hs.emplace_back(Line(a, b, c));
    mapY[a] = mapY[b] = mapX[c] = 0;
  }
  vector<int> xs, ys;
  for(auto& mx : mapX) {
    mx.second = xs.size();
    xs.emplace_back(mx.first);
  }
  for(auto& my : mapY) {
    my.second = ys.size();
    ys.emplace_back(my.first);
  }
  int xsz = xs.size(), ysz = ys.size();
  vector<vector<int> > dist(xsz*2, vector<int>(ysz*2, 0));
  for(const auto& l : vs) {
    for(int x = mapX[l.a]; x <= mapX[l.b]; x++) {
      dist[x*2+0][mapY[l.c]*2] = -1;
      if(x < mapX[l.b]) dist[x*2+1][mapY[l.c]*2] = -1;
    }
  }
  for(const auto& l : hs) {
    for(int y = mapY[l.a]; y <= mapY[l.b]; y++) {
      dist[mapX[l.c]*2][y*2+0] = -1;
      if(y < mapY[l.b]) dist[mapX[l.c]*2][y*2+1] = -1;
    }
  }
  queue<pair<int, int> > que;
  que.emplace(make_pair(mapX[0]*2+1, mapY[0]*2+1));
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  ll ans = 0;
  while(!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    if(dist[x][y] == -1) continue;
    if(dist[x][y] == 1) continue;
    dist[x][y] = 1;
    if(x % 2 && y % 2) {
      ans += abs(ll(xs[x/2]) - ll(xs[x/2+1])) * abs(ll(ys[y/2]) - ll(ys[y/2+1]));
    }
    rep(d, 4) {
      int nx = x + dx[d], ny = y + dy[d];
      if(dist[nx][ny] == -1) continue;
      if(dist[nx][ny] == 1) continue;
      if(nx == 0 || nx == xsz*2-1 || ny == 0 || ny == ysz*2-1) {
        cout << "INF\n";
        return;
      }
      que.push(make_pair(nx, ny));
    }
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}