#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
template <class T>
bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T>
T sqar(T x) {
  return x * x;
}
template <class T>
inline void princ(T x) {
  cout << x << " ";
};
template <class T>
inline void print(T x) {
  cout << x << "\n";
};
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int v_wall[1025][1025];
int h_wall[1025][1025];
int seen[1025][1025];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < (ll)n; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    if (abs(c) > 510) continue;
    if (a > 510 || b < -510) continue;
    b = min(b, 510ll);
    a = max(a, -510ll);
    fill(v_wall[c + 510] + a + 510, v_wall[c + 510] + b + 510, 1);
  }
  for (ll i = 0; i < (ll)m; i++) {
    ll d, e, f;
    cin >> d >> e >> f;
    if (abs(d) > 510) continue;
    if (e > 510 || f < -510) continue;
    f = min(f, 510ll);
    e = max(e, -510ll);
    fill(h_wall[d + 510] + e + 510, h_wall[d + 510] + f + 510, 1);
  }
  queue<PLL> que;
  ll ctr = 0;
  que.push(make_pair(510ll, 510ll));
  que.push(make_pair(509ll, 510ll));
  que.push(make_pair(510ll, 509ll));
  que.push(make_pair(509ll, 509ll));
  while (!que.empty()) {
    PLL pl = que.front();
    que.pop();
    if (seen[pl.first][pl.second]) continue;
    seen[pl.first][pl.second] = 1;
    ctr++;
    if (pl.first > 1010ll || pl.first < 10ll || pl.second > 1010ll ||
        pl.second < 10ll) {
      print("INF");
      return 0;
    }
    if (h_wall[pl.first][pl.second] == 0)
      que.push(make_pair(pl.first - 1, pl.second));
    if (h_wall[pl.first + 1][pl.second] == 0)
      que.push(make_pair(pl.first + 1, pl.second));
    if (v_wall[pl.second][pl.first] == 0)
      que.push(make_pair(pl.first, pl.second - 1));
    if (v_wall[pl.second + 1][pl.first] == 0)
      que.push(make_pair(pl.first, pl.second + 1));
  }
  print(ctr);
  return 0;
}
