#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Compress {
 private:
  map<T, int> _zip;
  map<int, T> _unzip;
  int sz;
  void init(vector<T> &xs) {
    set<T> st;
    for (const auto &x : xs) st.insert(x);
    sz = 0;
    for (auto iter = st.begin(); iter != st.end(); iter++) {
      _zip[*iter] = sz;
      _unzip[sz] = *iter;
      sz++;
    }
  }

 public:
  Compress() {}
  Compress(vector<T> &xs) { init(xs); }
  int zip(T x) { return _zip[x]; }
  T unzip(int x) { return _unzip[x]; }
  int size() { return sz; }
};
const int MAX = 1010;
const long long INF = 4e18 + 10;
const int DX[2] = {-1, 1};
int N, M;
int A[MAX], B[MAX], C[MAX], D[MAX], E[MAX], F[MAX];
vector<pair<long long, long long>> abOfC[3 * MAX], efOfD[3 * MAX];
long long solve() {
  vector<long long> xs, ys;
  xs.push_back(INF);
  xs.push_back(0);
  xs.push_back(-INF);
  ys.push_back(INF);
  ys.push_back(0);
  ys.push_back(-INF);
  for (long long i = 0; i < N; ++i) {
    xs.push_back(A[i]);
    xs.push_back(B[i]);
    ys.push_back(C[i]);
  }
  for (long long i = 0; i < M; ++i) {
    xs.push_back(D[i]);
    ys.push_back(E[i]);
    ys.push_back(F[i]);
  }
  Compress<long long> compressX(xs), compressY(ys);
  vector<vector<bool>> check(compressX.zip(INF) + 1,
                             vector<bool>(compressY.zip(INF) + 1, false));
  long long x0 = compressX.zip(0), y0 = compressY.zip(0);
  long long ans = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(x0, y0));
  check[x0][y0] = true;
  auto calc = [&compressX, &compressY, &ans](int x, int y) {
    if (ans == INF) return;
    if (x == 0 || x + 2 >= compressX.size() || y == 0 ||
        y + 2 >= compressY.size()) {
      ans = INF;
      return;
    }
    long long left = compressX.unzip(x), bottom = compressY.unzip(y);
    long long right = compressX.unzip(x + 1), top = compressY.unzip(y + 1);
    long long dx = right - left;
    long long dy = top - bottom;
    ans += dx * dy;
  };
  for (long long i = 0; i < N; ++i) {
    int a = compressX.zip(A[i]), b = compressX.zip(B[i]);
    int c = compressY.zip(C[i]);
    abOfC[c].push_back(make_pair(a, b));
  }
  for (long long i = 0; i < M; ++i) {
    int d = compressX.zip(D[i]);
    int e = compressY.zip(E[i]), f = compressY.zip(F[i]);
    efOfD[d].push_back(make_pair(e, f));
  }
  while (!que.empty()) {
    pair<int, int> cur;
    cur = que.front();
    que.pop();
    calc(cur.first, cur.second);
    if (ans == INF) return INF;
    for (long long k = 0; k < 2; ++k) {
      int x = cur.first, y = cur.second + DX[k];
      if (check[x][y]) continue;
      int c = max(y, cur.second);
      if (abs(compressX.unzip(x)) == INF || abs(compressY.unzip(c)) == INF)
        return INF;
      bool can = true;
      for (const auto &ab : abOfC[c]) can &= !(ab.first <= x && x < ab.second);
      if (!can) continue;
      que.push(make_pair(x, y));
      check[x][y] = true;
    }
    for (long long k = 0; k < 2; ++k) {
      int x = cur.first + DX[k], y = cur.second;
      if (check[x][y]) continue;
      int d = max(x, cur.first);
      if (abs(compressX.unzip(d)) == INF || abs(compressY.unzip(y)) == INF)
        return INF;
      bool can = true;
      for (const auto &ef : efOfD[d]) can &= !(ef.first <= y && y < ef.second);
      if (!can) continue;
      que.push(make_pair(x, y));
      check[x][y] = true;
    }
  }
  return ans;
}
int main() {
  cout << fixed << setprecision(15);
  cin >> N >> M;
  for (long long i = 0; i < N; ++i) cin >> A[i] >> B[i] >> C[i];
  for (long long i = 0; i < M; ++i) cin >> D[i] >> E[i] >> F[i];
  long long ans = solve();
  if (ans >= INF)
    cout << "INF" << endl;
  else
    cout << ans << endl;
}
