#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
void print() {}
template <class H, class... T>
void print(H&& h, T&&... t) {
  cout << h << " \n"[sizeof...(t) == 0];
  print(forward<T>(t)...);
}
bool check[2010][2010] = {};
bool line_yoko[2010][2010] = {};
bool line_tate[2010][2010] = {};
void solve() {
  ll N, M;
  cin >> N >> M;
  ll A[1010], B[1010], C[1010];
  ll D[1010], E[1010], F[1010];
  vector<ll> x, y;
  x.push_back(-INF);
  x.push_back(INF);
  y.push_back(-INF);
  y.push_back(INF);
  x.push_back(0);
  y.push_back(0);
  for (ll i = (0); i < (N); i++) {
    cin >> A[i] >> B[i] >> C[i];
    y.push_back(C[i]);
    x.push_back(A[i]);
    x.push_back(B[i]);
  }
  for (ll i = (0); i < (M); i++) {
    cin >> D[i] >> E[i] >> F[i];
    x.push_back(D[i]);
    y.push_back(E[i]);
    y.push_back(F[i]);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  vector<ll> diff_x, diff_y;
  ll sz_x = x.size();
  for (ll i = (0); i < (sz_x - 1); i++) {
    diff_x.push_back(x[i + 1] - x[i]);
  }
  ll sz_y = y.size();
  for (ll i = (0); i < (sz_y - 1); i++) {
    diff_y.push_back(y[i + 1] - y[i]);
  }
  for (ll i = (0); i < (N); i++) {
    A[i] = lower_bound(x.begin(), x.end(), A[i]) - x.begin();
    B[i] = lower_bound(x.begin(), x.end(), B[i]) - x.begin();
    C[i] = lower_bound(y.begin(), y.end(), C[i]) - y.begin();
  }
  for (ll i = (0); i < (M); i++) {
    D[i] = lower_bound(x.begin(), x.end(), D[i]) - x.begin();
    E[i] = lower_bound(y.begin(), y.end(), E[i]) - y.begin();
    F[i] = lower_bound(y.begin(), y.end(), F[i]) - y.begin();
  }
  for (ll i = (0); i < (N); i++) {
    for (ll j = (A[i]); j < (B[i]); j++) {
      line_tate[j][C[i]] = true;
    }
  }
  for (ll i = (0); i < (M); i++) {
    for (ll j = (E[i]); j < (F[i]); j++) {
      line_yoko[D[i]][j] = true;
    }
  }
  queue<lpair> que;
  ll x0 = lower_bound(x.begin(), x.end(), 0) - x.begin();
  ll y0 = lower_bound(y.begin(), y.end(), 0) - y.begin();
  que.push({x0, y0});
  bool ok = true;
  while (not que.empty()) {
    lpair l1 = que.front();
    que.pop();
    ll x = l1.first, y = l1.second;
    if (x > 2000 || y > 2000) {
      ok = false;
      break;
    }
    if (x < 0 || y < 0) continue;
    if (check[x][y]) continue;
    check[x][y] = true;
    if (not line_yoko[x + 1][y]) {
      if (not check[x + 1][y]) que.push({x + 1, y});
    }
    if (not line_yoko[x][y]) {
      if (not check[x - 1][y]) que.push({x - 1, y});
    }
    if (not line_tate[x][y + 1]) {
      if (not check[x][y + 1]) que.push({x, y + 1});
    }
    if (not line_tate[x][y]) {
      if (not check[x][y - 1]) que.push({x, y - 1});
    }
  }
  if (not ok) {
    print("INF");
    return;
  }
  ll ans = 0;
  for (ll i = (0); i < (2001); i++) {
    for (ll j = (0); j < (2001); j++) {
      if (check[i][j]) {
        ans += diff_x[i] * diff_y[j];
      }
    }
  }
  print(ans);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
