#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
std::ostream& operator<<(std::ostream& out, const std::pair<S, T>& a) {
  std::cout << '(' << a.first << ", " << a.second << ')';
  return out;
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
  std::cout << '[';
  for (ll i = (0); i < (a.size()); ++i) {
    std::cout << a[i];
    if (i != a.size() - 1) std::cout << ", ";
  }
  std::cout << ']';
  return out;
}
ll N, M;
std::vector<ll> xs, ys;
ll A[1010], B[1010], C[1010];
ll D[1010], E[1010], F[1010];
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
bool used[2020][2020][4];
std::map<ll, ll> ixs, iys;
ll dist[2020][2020];
int main() {
  std::cin >> N >> M;
  for (ll i = (0); i < (N); ++i) {
    std::cin >> A[i] >> B[i] >> C[i];
    xs.emplace_back(A[i]);
    xs.emplace_back(B[i]);
    ys.emplace_back(C[i]);
  }
  for (ll i = (0); i < (M); ++i) {
    std::cin >> D[i] >> E[i] >> F[i];
    xs.emplace_back(D[i]);
    ys.emplace_back(E[i]);
    ys.emplace_back(F[i]);
  }
  xs.emplace_back(0);
  xs.emplace_back(2e9);
  xs.emplace_back(-2e9);
  ys.emplace_back(0);
  ys.emplace_back(2e9);
  ys.emplace_back(-2e9);
  std::sort((xs).begin(), (xs).end());
  std::sort((ys).begin(), (ys).end());
  xs.erase(std::unique((xs).begin(), (xs).end()), xs.end());
  ys.erase(std::unique((ys).begin(), (ys).end()), ys.end());
  for (ll i = (0); i < (xs.size()); ++i) ixs[xs[i]] = i;
  for (ll i = (0); i < (ys.size()); ++i) iys[ys[i]] = i;
  for (ll i = (0); i < (N); ++i) {
    for (ll j = (ixs[A[i]]); j < (ixs[B[i]]); ++j) {
      used[j][iys[C[i]]][3] = true;
      used[j][iys[C[i]] - 1][1] = true;
    }
  }
  for (ll i = (0); i < (M); ++i) {
    for (ll j = (iys[E[i]]); j < (iys[F[i]]); ++j) {
      used[ixs[D[i]]][j][2] = true;
      used[ixs[D[i]] - 1][j][0] = true;
    }
  }
  std::queue<P> que;
  que.emplace(ixs[0], iys[0]);
  for (ll i = (0); i < (xs.size() + 5); ++i)
    for (ll j = (0); j < (ys.size() + 5); ++j) dist[i][j] = INF;
  dist[ixs[0]][iys[0]] = 0;
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    ll i = p.first, j = p.second;
    for (ll d = (0); d < (4); ++d)
      if (!used[i][j][d]) {
        ll ni = i + dx[d], nj = j + dy[d];
        if (ni >= 0 && ni < xs.size() && nj >= 0 && nj < ys.size() &&
            dist[ni][nj] == INF) {
          dist[ni][nj] = dist[i][j] + 1;
          que.emplace(ni, nj);
        }
      }
  }
  ll w = xs.size() - 1;
  ll h = ys.size() - 1;
  ll ans = 0;
  for (ll i = (0); i < (w); ++i)
    for (ll j = (0); j < (h); ++j)
      if (dist[i + 1][j + 1] != INF) {
        if (!i || i == w - 1 || !j || j == h - 1) {
          std::cout << "INF" << std::endl;
          return 0;
        }
        ans += (xs[i + 1] - xs[i]) * (ys[i + 1] - ys[i]);
      }
  std::cout << ans << std::endl;
  return 0;
}
