#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = (long long)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
vector<long long> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vector<long long> dx2 = {1, 1, 0, -1, -1, -1, 0, 1},
                  dy2 = {0, 1, 1, 1, 0, -1, -1, -1};
const long long MOD = 1000000007;
class UnionFind {
 public:
  long long n;
  vector<long long> par;
  vector<long long> ran;
  vector<long long> num;
  long long g;
  UnionFind(long long _n) {
    n = _n;
    g = n;
    par.resize(n);
    ran.resize(n);
    num.resize(n);
    for (long long i = 0; i < n; i++) {
      par[i] = i;
      ran[i] = 0;
      num[i] = 1;
    }
  }
  long long find(long long x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    long long numsum = num[x] + num[y];
    if (x == y) {
      return;
    }
    if (ran[x] < ran[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (ran[x] == ran[y]) {
        ran[x]++;
      }
    }
    num[x] = num[y] = numsum;
    g--;
  }
  bool same(long long x, long long y) { return find(x) == find(y); }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  long long n, m;
  cin >> n >> m;
  using P = pair<long long, pair<long long, long long>>;
  vector<P> ylr(m), xud(n);
  set<long long> yst, xst;
  for (long long i = -1; i <= 1; i++) {
    yst.insert(i);
    xst.insert(i);
  }
  yst.insert(-INF);
  yst.insert(INF);
  xst.insert(-INF);
  xst.insert(INF);
  map<long long, vector<pair<long long, long long>>> y2lr, x2ud;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> xud[i].second.first >> xud[i].second.second >> xud[i].first;
    xst.insert(xud[i].first);
    yst.insert(xud[i].second.first);
    yst.insert(xud[i].second.second);
    x2ud[xud[i].first].push_back(xud[i].second);
  }
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> ylr[i].first >> ylr[i].second.first >> ylr[i].second.second;
    yst.insert(ylr[i].first);
    xst.insert(ylr[i].second.first);
    xst.insert(ylr[i].second.second);
    y2lr[ylr[i].first].push_back(ylr[i].second);
  }
  for (auto itr = y2lr.begin(); itr != y2lr.end(); itr++) {
    sort(itr->second.begin(), itr->second.end());
    vector<pair<long long, long long>> lr;
    for (pair<long long, long long> temp : itr->second) {
      if (lr.size() == 0 or lr.back().second < temp.first)
        lr.push_back(temp);
      else
        lr.back().second = temp.second;
    }
    itr->second = lr;
  }
  for (auto itr = x2ud.begin(); itr != x2ud.end(); itr++) {
    sort(itr->second.begin(), itr->second.end());
    vector<pair<long long, long long>> lr;
    for (pair<long long, long long> temp : itr->second) {
      if (lr.size() == 0 or lr.back().second < temp.first)
        lr.push_back(temp);
      else
        lr.back().second = temp.second;
    }
    itr->second = lr;
  }
  vector<pair<long long, long long>> lr, ud;
  auto itr = xst.begin();
  long long pre = *itr;
  xst.erase(itr);
  while (xst.size()) {
    auto itr = xst.begin();
    long long x = *itr;
    xst.erase(itr);
    lr.push_back(pair<long long, long long>(pre, x));
    pre = x;
  }
  itr = yst.begin();
  pre = *itr;
  yst.erase(itr);
  while (yst.size()) {
    auto itr = yst.begin();
    long long y = *itr;
    yst.erase(itr);
    ud.push_back(pair<long long, long long>(pre, y));
    pre = y;
  }
  long long h = ud.size(), w = lr.size();
  UnionFind uf(h * w);
  for (long long i = 1; i < h - 1; i++) {
    for (long long j = 1; j < w - 1; j++) {
      long long u = i * w + j;
      long long left = lr[j].first, right = lr[j].second;
      long long up = ud[i].first, down = ud[i].second;
      for (long long k = 0; k < (long long)(4); k++) {
        long long ni = i + dy[k], nj = j + dx[k];
        long long v = ni * w + nj;
        bool flag = true;
        if (k == 0) {
          long long x = lr[j].second;
          auto itr = lower_bound(x2ud[x].begin(), x2ud[x].end(),
                                 pair<long long, long long>(up + 1, -INF));
          if (itr != x2ud[x].begin()) {
            itr--;
            if (itr->second >= down) flag = false;
          }
        }
        if (k == 1) {
          long long y = ud[i].second;
          auto itr = lower_bound(y2lr[y].begin(), y2lr[y].end(),
                                 pair<long long, long long>(left + 1, -INF));
          if (itr != y2lr[y].begin()) {
            itr--;
            if (itr->second >= right) flag = false;
          }
        }
        if (k == 2) {
          long long x = lr[j].first;
          auto itr = lower_bound(x2ud[x].begin(), x2ud[x].end(),
                                 pair<long long, long long>(up + 1, -INF));
          if (itr != x2ud[x].begin()) {
            itr--;
            if (itr->second >= down) flag = false;
          }
        }
        if (k == 3) {
          long long y = ud[i].first;
          auto itr = lower_bound(y2lr[y].begin(), y2lr[y].end(),
                                 pair<long long, long long>(left + 1, -INF));
          if (itr != y2lr[y].begin()) {
            itr--;
            if (itr->second >= right) flag = false;
          }
        }
        if (flag) {
          uf.unite(u, v);
        }
      }
    }
  }
  long long root;
  for (long long i = 0; i < (long long)(h); i++) {
    for (long long j = 0; j < (long long)(w); j++) {
      if (lr[i].first == 0 and ud[j].first == 0) {
        root = i * w + j;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)(h); i++) {
    for (long long j = 0; j < (long long)(w); j++) {
      long long u = i * w + j;
      long long left = lr[i].first, right = lr[i].second;
      long long up = ud[i].first, down = ud[i].second;
      if (uf.find(u) == uf.find(root)) {
        if (abs(left) == INF or abs(right) == INF or abs(up) == INF or
            abs(down) == INF) {
          cout << "INF" << endl;
          return 0;
        }
        ans += (right - left) * (down - up);
      }
    }
  }
  cout << ans << endl;
}
