#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;
}
template <class T>
inline T powerM(T a, T b) {
  if (b == 0) return 1;
  T tmp = powerM(a, b / 2);
  if (b % 2 == 0)
    return tmp * tmp % MOD;
  else
    return tmp * tmp % MOD * a % MOD;
}
template <class T>
inline T power(T a, T b, T m) {
  if (b == 0) return 1;
  T tmp = power(a, b / 2, m);
  if (b % 2 == 0)
    return tmp * tmp % m;
  else
    return tmp * tmp % m * a % m;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
inline T extgcd(T a, T b, T &x, T &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  T d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
void hey() { cout << "hey" << endl; }
template <class T>
struct edge {
  int to;
  T cost;
};
int N, M;
int compress(vector<ll> &x1, vector<ll> &x2, vector<ll> &x3,
             vector<ll> &xcomp) {
  int n1 = x1.size();
  int n2 = x2.size();
  int n3 = x3.size();
  for (int i = 0; i < (int)(n1); i++) {
    xcomp.push_back(x1[i]);
    xcomp.push_back(x1[i] + 1);
  }
  for (int i = 0; i < (int)(n2); i++) {
    xcomp.push_back(x2[i]);
    xcomp.push_back(x2[i] + 1);
  }
  for (int i = 0; i < (int)(n3); i++) {
    xcomp.push_back(x3[i]);
    xcomp.push_back(x3[i] + 1);
  }
  xcomp.push_back(-1000000003);
  xcomp.push_back(1000000003);
  xcomp.push_back(0);
  sort(xcomp.begin(), xcomp.end());
  xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
  for (int i = 0; i < (int)(n1); i++)
    x1[i] = lower_bound(xcomp.begin(), xcomp.end(), x1[i]) - xcomp.begin();
  for (int i = 0; i < (int)(n2); i++)
    x2[i] = lower_bound(xcomp.begin(), xcomp.end(), x2[i]) - xcomp.begin();
  for (int i = 0; i < (int)(n3); i++)
    x3[i] = lower_bound(xcomp.begin(), xcomp.end(), x3[i]) - xcomp.begin();
  return xcomp.size();
}
int main() {
  cin >> N >> M;
  vector<ll> A(N), B(N), C(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i] >> B[i] >> C[i];
  vector<ll> D(M), E(M), F(M);
  for (int i = 0; i < (int)(M); i++) cin >> D[i] >> E[i] >> F[i];
  vector<ll> xcomp, ycomp;
  int n2 = compress(A, B, D, xcomp);
  int m2 = compress(C, E, F, ycomp);
  vector<vector<bool>> seen(n2, vector<bool>(m2, false));
  vector<vector<bool>> dame(n2, vector<bool>(m2, false));
  queue<pair<int, int>> que;
  for (int i = 0; i < N; i++) {
    int x1 = A[i];
    int x2 = B[i];
    int y1 = C[i];
    for (int xx = x1; xx <= x2; xx++) dame[xx][y1] = true;
  }
  for (int i = 0; i < M; i++) {
    int x1 = D[i];
    int y1 = E[i];
    int y2 = F[i];
    for (int yy = y1; yy <= y2; yy++) dame[x1][yy] = true;
  }
  int x0 = lower_bound(xcomp.begin(), xcomp.end(), 0) - xcomp.begin();
  int y0 = lower_bound(ycomp.begin(), ycomp.end(), 0) - ycomp.begin();
  seen[x0][y0] = true;
  que.push({x0, y0});
  bool infinite = false;
  while (!que.empty()) {
    pair<int, int> xy = que.front();
    que.pop();
    int x = xy.first, y = xy.second;
    for (int d = 0; d < x4.size(); d++) {
      int nx = x + x4[d];
      int ny = y + y4[d];
      if (nx < 0 || nx >= n2 || ny < 0 || ny >= m2) continue;
      if (seen[nx][ny]) continue;
      if (dame[nx][ny]) continue;
      seen[nx][ny] = true;
      que.push({nx, ny});
      if (nx == 0 || ny == 0) {
        infinite = true;
      }
      if (nx == n2 - 1 || ny == m2 - 1) infinite = true;
    }
  }
  if (infinite) {
    cout << "INF" << endl;
    return 0;
  }
  ll res = 0;
  for (int x = 0; x < n2; x++) {
    for (int y = 0; y < m2; y++) {
      if (!seen[x][y]) continue;
      ll xsub = xcomp[x + 1] - xcomp[x];
      ll ysub = ycomp[y + 1] - ycomp[y];
      res += xsub * ysub;
    }
  }
  cout << res << endl;
}
