#include <bits/stdc++.h>
using namespace std;
const long long int INF = 999999999999999;
const long long int MOD = 1000000007;
const long long int MAX_N = 1010010;
long long int a, b, c, d, e, f, h, x, y, z, p, q, m, n, t, r, k, w, l, ans, i,
    j;
string S, T;
vector<long long int> A, B;
map<long long int, long long int> M1, M2;
vector<pair<long long int, pair<long long int, long long int>>> VP1, VP2;
vector<long long int> g[MAX_N];
vector<long long int> visited(MAX_N, 0);
void dfs(long long int x) {
  visited[x] = 1;
  for (long long int i : g[x]) {
    if (visited[i] == 0) {
      dfs(i);
    }
  }
}
void solve() {
  sort(VP1.begin(), VP1.end());
  sort(VP2.begin(), VP2.end());
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  x = VP1.size() + 1;
  y = VP2.size() + 1;
  for (long long int i = 0; i < long long int(x - 1); i++) {
    a = VP1[i].second.first;
    b = VP1[i].second.second;
    p = lower_bound(B.begin(), B.end(), a) - B.begin();
    q = upper_bound(B.begin(), B.end(), b) - B.begin() - 1;
    for (long long int j = 0; j < long long int(y); j++) {
      if (j < p || q <= j) {
        g[i * y + j].push_back((i + 1) * y + j);
        g[(i + 1) * y + j].push_back(i * y + j);
      }
    }
  }
  for (long long int i = 0; i < long long int(y - 1); i++) {
    a = VP2[i].second.first;
    b = VP2[i].second.second;
    p = lower_bound(A.begin(), A.end(), a) - A.begin();
    q = upper_bound(A.begin(), A.end(), b) - A.begin() - 1;
    for (long long int j = 0; j < long long int(x); j++) {
      if (j < p || q <= j) {
        g[j * y + i].push_back(j * y + i + 1);
        g[j * y + i + 1].push_back(j * y + i);
      }
    }
  }
  a = lower_bound(A.begin(), A.end(), 0) - A.begin() - 1;
  b = lower_bound(B.begin(), B.end(), 0) - B.begin() - 1;
  dfs(a * y + b);
  if (visited[0]) {
    cout << "INF"
         << "\n";
    return;
  }
  for (long long int i = 0; i < long long int(x); i++) {
    for (long long int j = 0; j < long long int(y); j++) {
      if (visited[i * y + j]) ans += (A[i + 1] - A[i]) * (B[j + 1] - B[j]);
    }
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x >> y;
  A.push_back(-2000000000);
  B.push_back(-2000000000);
  A.push_back(2000000000);
  B.push_back(2000000000);
  for (long long int i = 0; i < long long int(x); i++) {
    cin >> a >> b >> c;
    VP1.push_back({c, {a, b}});
    A.push_back(c);
  }
  for (long long int i = 0; i < long long int(y); i++) {
    cin >> a >> b >> c;
    VP2.push_back({a, {b, c}});
    B.push_back(a);
  }
  solve();
}
