#include<bits/stdc++.h>
using namespace std;

using LL = long long;
struct Segment {LL x, m, y;};

enum {L, U, R, D};
const int NEXT[5] = {0, -1, 0, 1, 0};

const LL INF = 9e18;

LL CX[3003], CY[3003], SX, SY;
bool used[3003][3003], ng[4][3003][3003];
LL dfs(auto i, auto j) {
  if(i==0 || i==SX-2 || j==0 || j==SY-2) return INF;
  if(used[i][j]) return 0ll;
  used[i][j] = true;
  auto lx = CX[i], hx = CX[i+1];
  auto ly = CY[j], hy = CY[j+1];
  auto res = (hx-lx) * (hy-ly);
  for(auto k=0; k<4; ++k) if(!ng[k][i][j]) {
    auto ni=i+NEXT[k], nj=j+NEXT[k+1];
    if(ni<0 || SX-2<ni || nj<0 || SY-2<nj) continue;
    if(used[ni][nj]) continue;
    auto area = dfs(ni, nj);
    if(area == INF) return INF;
    res += area;
  }
  return res;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<Segment> V(N), H(M);
  for(auto p: {&V, &H}) for(auto& s: *p) cin >> s.x >> s.m >> s.y;

  set<LL> X={-INF, 0, INF}, Y={-INF, 0, INF};
  for(auto& s: V) {
    X.emplace(s.x);
    X.emplace(s.m);
    Y.emplace(s.y);
  }
  for(auto& s: H) {
    X.emplace(s.x);
    Y.emplace(s.m);
    Y.emplace(s.y);
  }
  for(auto i: X) CX[SX++] = i;
  for(auto i: Y) CY[SY++] = i;

  auto index = [](auto& c, auto n, auto v) {return lower_bound(c, c+n, v) - c;};

  for(const auto& s: V) for(auto x=index(CX, SX, s.x), y=index(CY, SY, s.y); x<index(CX, SX, s.m); ++x) ng[R][x][y-1] = ng[L][x][y] = true;
  for(const auto& s: H) for(auto x=index(CX, SX, s.x), y=index(CY, SY, s.m); y<index(CY, SY, s.y); ++y) ng[D][x-1][y] = ng[U][x][y] = true;

  auto area = dfs(index(CX, SX, 0), index(CY, SY, 0));
  if(area != INF) cout << area << endl;
  else            cout << "INF" << endl;
}
