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

using Size = int;
template<typename T> class Compression {
 public:
  Compression(const std::vector<T>& list) : value_(list) {
    std::sort(begin(value_), end(value_));
    value_.erase(std::unique(begin(value_), end(value_)), end(value_));
    for(Size i = 0; i < value_.size(); ++i) index_[value_[i]] = i;
  }
  Size size() const {return value_.size();}
  Size index(const T& v) const {return index_.at(v);}
  T operator[](const Size i) const {return value_.at(i);}
 private:
  std::unordered_map<T, Size> index_;
  std::vector<T> value_;
};

int main() {
  using LL = long long;
  struct Segment {LL x, m, y;};
  const LL INF = 9e18;

  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;

  vector<LL> P = {-INF, 0, INF};
  for(auto p: {&V, &H}) for(auto& s: *p) {
    P.emplace_back(s.x);
    P.emplace_back(s.m);
    P.emplace_back(s.y);
  }
  Compression C(P);

  // (0,-1) -> (-1,0) -> (0,1) -> (1,0)
  enum {L, U, R, D};
  const int NEXT[5] = {0, -1, 0, 1, 0};
  vector<vector<vector<bool>>> ng(4, vector<vector<bool>>(C.size()-1, vector<bool>(C.size()-1)));
  for(const auto& s: V) for(auto x=C.index(s.x), y=C.index(s.y); x<C.index(s.m); ++x) ng[R][x][y-1] = ng[L][x][y] = true;
  for(const auto& s: H) for(auto x=C.index(s.x), y=C.index(s.m); y<C.index(s.y); ++y) ng[D][x-1][y] = ng[U][x][y] = true;

  vector<vector<bool>> used(C.size()-1, vector<bool>(C.size()-1));
  function<LL(int,int)> dfs = [&](auto i, auto j) {
    if(i==0 || j==0 || i==C.size()-2 || j==C.size()-2) return INF;
    if(used[i][j]) return 0ll;
    used[i][j] = true;
    auto lx = C[i], hx = C[i+1];
    auto ly = C[j], hy = C[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]);
      if(area == INF) return INF;
      res += area;
    }
    return res;
  };

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