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

using Size = int;
template<typename T> class Compression {
 public:
  Compression(const set<T>& list) : value_(begin(list), end(list)) {}
  Size size() const {return value_.size();}
  Size index(const T& v) const {return lower_bound(begin(value_), end(value_), v) - begin(value_);}
  T operator[](const Size i) const {return value_.at(i);}
 private:
  std::vector<T> value_;
};

using LL = long long;

const LL INF = 9e18;

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

bool used[3003][3003], ng[4][3003][3003];
LL dfs(auto i, auto j, auto& CX, auto& CY, auto SX, auto SY) {
  if(i==0 || i==SX-1 || j==0 || j==SY-1) 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 area = dfs(i+NEXT[k], j+NEXT[k+1], CX, CY, SX, SY);
    if(area == INF) return INF;
    res += area;
  }
  return res;
};

int main() {
  struct Segment {LL x, m, y;};

  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);
  }
  Compression CX(X), CY(Y);

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

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