#include <bits/stdc++.h>
using namespace std;
int x[4] = {1, 0, -1, 0};
int y[4] = {0, 1, 0, -1};
pair<int, int> edge[4] = {{1, 0}, {0, 0}, {0, 0}, {0, -1}};
const int N = 2010;
int seg[N][N][2];
set<pair<int, int>> visited;
int main() {
  int n, m;
  cin >> n >> m;
  int xl = INT_MAX;
  int yl = INT_MAX;
  int xr = INT_MIN;
  int yr = INT_MIN;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a += 1000;
    b += 1000;
    c += 1000;
    for (int j = min(a, b) + 1; j <= max(a, b); j++) {
      seg[c][j][1] = 1;
    }
    xl = min({xl, c});
    xr = max({xr, c});
    yl = min({yl, a, b});
    yr = max({yr, a, b});
  }
  for (int i = 0; i < m; i++) {
    int d, e, f;
    cin >> d >> e >> f;
    d += 1000;
    e += 1000;
    f += 1000;
    for (int j = min(e, f); j <= max(e, f) - 1; j++) {
      seg[j][d][0] = 1;
    }
    xl = min({xl, e, f});
    xr = max({xr, e, f});
    yl = min({yl, d});
    yr = max({yr, d});
  }
  xl -= 10;
  xr += 10;
  yl -= 10;
  yr += 10;
  int ans = 0;
  queue<pair<int, int>> q;
  q.push({1000, 1000});
  visited.insert({1000, 1000});
  ans++;
  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    for (int k = 0; k < 4; k++) {
      int xx = u.first + x[k];
      int yy = u.second + y[k];
      if (xx == xl or xx == xr or yy == yl or yy == yr) {
        cout << "INF" << endl;
        return 0;
      }
      pair<int, int> p = {xx, yy};
      pair<int, int> e = edge[k];
      if ((seg[u.first + e.first][u.second + e.second][k % 2 == 0]) or
          visited.count(p))
        continue;
      q.push(p);
      visited.insert(p);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
