#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)...);
}
ll get(ll x, ll y) { return x * 2000 + y; }
bool visit[2010][2010] = {};
void solve() {
  ll N, M;
  cin >> N >> M;
  ll thre = 100;
  ll A[1010], B[1010], C[1010];
  ll D[1010], E[1010], F[1010];
  map<lpair, bool> is_line;
  for (ll i = (0); i < (N); i++) {
    cin >> A[i] >> B[i] >> C[i];
    A[i] += thre;
    B[i] += thre;
    C[i] += thre;
    for (ll j = (A[i]); j < (B[i]); j++) {
      ll v1 = get(j, C[i]), v2 = get(j + 1, C[i]);
      is_line[{v1, v2}] = true;
      is_line[{v2, v1}] = true;
    }
  }
  for (ll i = (0); i < (M); i++) {
    cin >> D[i] >> E[i] >> F[i];
    D[i] += thre;
    E[i] += thre;
    F[i] += thre;
    for (ll j = (E[i]); j < (F[i]); j++) {
      ll v1 = get(D[i], j), v2 = get(D[i], j + 1);
      is_line[{v1, v2}] = true;
      is_line[{v2, v1}] = true;
    }
  }
  queue<lpair> que;
  que.push({thre, thre});
  ll dx[4] = {0, 0, 1, -1};
  ll dy[4] = {1, -1, 0, 0};
  while (not que.empty()) {
    lpair l1 = que.front();
    que.pop();
    ll x = l1.first, y = l1.second;
    if (x < 0 || y < 0 || x > 3 * thre || y > 3 * thre) continue;
    if (visit[x][y]) continue;
    visit[x][y] = true;
    if (not is_line[{get(x + 1, y), get(x + 1, y + 1)}]) {
      if (not visit[x + 1][y]) que.push({x + 1, y});
    }
    if (not is_line[{get(x, y), get(x, y + 1)}]) {
      if (not visit[x - 1][y]) que.push({x - 1, y});
    }
    if (not is_line[{get(x + 1, y + 1), get(x, y + 1)}]) {
      if (not visit[x][y + 1]) que.push({x, y + 1});
    }
    if (not is_line[{get(x + 1, y), get(x, y)}]) {
      if (not visit[x][y - 1]) que.push({x, y - 1});
    }
  }
  ll ans = 0;
  for (ll i = (0); i < (thre * 2 + 1); i++) {
    for (ll j = (0); j < (thre * 2 + 1); j++) {
      if (visit[i][j]) ans++;
    }
  }
  if (visit[3 * thre][3 * thre]) {
    print("INF");
  } else {
    print(ans);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
