#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& t : v) {
    is >> t;
  }
  return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T t : v) {
    os << t << " ";
  }
  os << "\n";
  return os;
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(m), e(m), f(m);
  vector<int> row, col;
  row.push_back(0);
  col.push_back(0);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i] >> b[i] >> c[i];
    col.push_back(c[i] - 1);
    col.push_back(c[i]);
    row.push_back(a[i] - 1);
    row.push_back(a[i]);
    row.push_back(b[i]);
    row.push_back(b[i] - 1);
  }
  for (int i = 0; i < (m); ++i) {
    cin >> d[i] >> e[i] >> f[i];
    row.push_back(d[i]);
    row.push_back(d[i] - 1);
    col.push_back(e[i]);
    col.push_back(e[i] - 1);
    col.push_back(f[i]);
    col.push_back(f[i] - 1);
  }
  sort(row.begin(), row.end());
  sort(col.begin(), col.end());
  row.erase(unique(row.begin(), row.end()), row.end());
  col.erase(unique(col.begin(), col.end()), col.end());
  int h = row.size();
  int w = col.size();
  vector<vector<int>> ri(h, vector<int>(w, 0));
  vector<vector<int>> lo(h, vector<int>(w, 0));
  for (int i = 0; i < (n); ++i) {
    int na = a[i], nb = b[i], nc = c[i];
    na = lower_bound(row.begin(), row.end(), na) - row.begin();
    nb = lower_bound(row.begin(), row.end(), nb) - row.begin();
    nc = lower_bound(col.begin(), col.end(), nc) - col.begin();
    nc--;
    while (na < nb) {
      ri[na][nc] = 1;
      na++;
    }
  }
  for (int i = 0; i < (m); ++i) {
    int nd = d[i], ne = e[i], nf = f[i];
    nd = lower_bound(row.begin(), row.end(), nd) - row.begin();
    ne = lower_bound(col.begin(), col.end(), ne) - col.begin();
    nf = lower_bound(col.begin(), col.end(), nf) - col.begin();
    nd--;
    while (ne < nf) {
      lo[nd][ne] = 1;
      ne++;
    }
  }
  vector<vector<int>> able(h, vector<int>(w, 0));
  vector<vector<int>> seen(h, vector<int>(w, 0));
  int sh = lower_bound(row.begin(), row.end(), 0) - row.begin();
  int sw = lower_bound(col.begin(), col.end(), 0) - col.begin();
  able[sh][sw] = 1;
  queue<P> q;
  q.emplace(sh, sw);
  auto add = [&](int nh, int nw) {
    if (seen[nh][nw]) return;
    able[nh][nw] = 1;
    q.emplace(nh, nw);
  };
  while (!q.empty()) {
    int nh = q.front().first;
    int nw = q.front().second;
    q.pop();
    seen[nh][nw] = 1;
    if (nh + 1 < h && !lo[nh][nw]) add(nh + 1, nw);
    if (nw + 1 < w && !ri[nh][nw]) add(nh, nw + 1);
    if (nh > 0 && !lo[nh - 1][nw]) add(nh - 1, nw);
    if (nw > 0 && !ri[nh][nw - 1]) add(nh, nw - 1);
  }
  ll ans = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      if (!able[i][j]) continue;
      if (i == 0 || i == h - 1 || j == 0 || j == w - 1) {
        cout << "INF" << endl;
        return 0;
      }
      int hig = row[i + 1] - row[i];
      int wid = col[j + 1] - col[j];
      ans += (ll)hig * wid;
    }
  cout << ans << endl;
}
