#include <bits/stdc++.h>
using namespace std;
long long N, M;
vector<tuple<long long, long long, long long>> ABC, DEF;
const long long INF = 1e9 + 1;
vector<long long> X, Y;
long long NX, NY;
map<long long, long long> IX, IY;
set<pair<long long, long long>> H, V;
queue<pair<long long, long long>> Q;
set<pair<long long, long long>> A;
long long Res;
int main() {
  cin >> N >> M;
  ABC.resize(N);
  for (long long i = 0; i < N; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    ABC.push_back({a, b, c});
    X.push_back(a);
    X.push_back(b);
    Y.push_back(c);
  }
  DEF.resize(M);
  for (long long i = 0; i < M; ++i) {
    long long d, e, f;
    cin >> d >> e >> f;
    DEF.push_back({d, e, f});
    X.push_back(d);
    Y.push_back(e);
    Y.push_back(f);
  }
  X.push_back(0);
  X.push_back(INF);
  X.push_back(-INF);
  Y.push_back(0);
  Y.push_back(INF);
  Y.push_back(-INF);
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  sort(Y.begin(), Y.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  long long NX = X.size(), NY = Y.size();
  for (long long i = 0; i < NX; ++i) IX[X[i]] = i;
  for (long long i = 0; i < NY; ++i) IY[Y[i]] = i;
  for (auto abc : ABC) {
    long long a, b, c;
    tie(a, b, c) = abc;
    a = IX[a];
    b = IX[b];
    c = IY[c];
    for (long long x = a; x < b; ++x) H.insert({x, c});
  }
  for (auto def : DEF) {
    long long d, e, f;
    tie(d, e, f) = def;
    d = IX[d];
    e = IY[e];
    f = IY[f];
    for (long long y = e; y < f; ++y) V.insert({d, y});
  }
  for (long long x = 0; x < NX - 1; ++x) {
    H.insert({x, 0});
    H.insert({x, NY - 1});
  }
  for (long long y = 0; y < NY - 1; ++y) {
    V.insert({0, y});
    V.insert({NX - 1, y});
  }
  Q.push({IX[0], IY[0]});
  while (!Q.empty()) {
    auto xy = Q.front();
    Q.pop();
    if (A.count(xy)) continue;
    A.insert(xy);
    long long x, y;
    tie(x, y) = xy;
    Res += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y]);
    if (!H.count({x, y + 1})) Q.push({x, y + 1});
    if (!H.count({x, y})) Q.push({x, y - 1});
    if (!V.count({x + 1, y})) Q.push({x + 1, y});
    if (!V.count({x, y})) Q.push({x - 1, y});
  }
  if (A.count({0, 0}))
    cout << "INF" << endl;
  else
    cout << Res << endl;
  return 0;
}
