#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
#pragma GCC optimize("fast-math")
using namespace std;
const long long mod = 1e9 + 7, mod2 = 998244353;
const long double eps = 1e-6;
const long long inf = 1e18;
const int base = 1e9;
const long double PI = 3.1415926;
void deb(long double first){};
int n, m;
int vx1[3001], vx2[3001], vy[3001];
int hx[3001], hy1[3001], hy2[3001];
bool ngx[3001][3001], ngy[3001][3001];
vector<int> first, second;
queue<pair<int, int>> q;
long long ans = INT64_MAX;
unsigned int bitcount(unsigned long long val) {
  return __builtin_popcount(val) + __builtin_popcount(val >> 32);
}
void local() { freopen("test.in", "r", stdin); }
void remote() {}
void read() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x1, x2, yy;
    cin >> x1 >> x2 >> yy;
    first.push_back(x1), first.push_back(x2), second.push_back(yy);
    vx1[i] = x1;
    vx2[i] = x2;
    vy[i] = yy;
  }
  for (int i = 0; i < m; i++) {
    int xx, yy, yyy;
    cin >> xx >> yy >> yyy;
    first.push_back(xx), second.push_back(yy), second.push_back(yyy);
    hx[i] = xx;
    hy1[i] = yy;
    hy2[i] = yyy;
  }
}
int ind(int val, const vector<int> &v) {
  return lower_bound(v.begin(), v.end(), val) - v.begin();
}
int main() {
  remote();
  read();
  sort(first.begin(), first.end());
  sort(second.begin(), second.end());
  first.erase(unique(first.begin(), first.end()), first.end()),
      second.erase(unique(second.begin(), second.end()), second.end());
  for (int i = 0; i < n; i++) {
    int from = ind(vx1[i], first);
    int to = ind(vx2[i], first);
    int yy = ind(vy[i], second);
    for (int j = from; j < to; j++) ngx[j][yy] = true;
  }
  for (int i = 0; i < m; i++) {
    int from = ind(hy1[i], second);
    int to = ind(hy2[i], second);
    int xx = ind(hx[i], first);
    for (int j = from; j < to; j++) ngy[xx][j] = true;
  }
  n = first.size(), m = second.size();
  int start_v = lower_bound(first.begin(), first.end(), 0) - first.begin() - 1;
  int start_h =
      lower_bound(second.begin(), second.end(), 0) - second.begin() - 1;
  q.push({start_v, start_h});
  long long ans = 0;
  vector<vector<bool>> u(n, vector<bool>(m, false));
  while (!q.empty()) {
    const pair<int, int> &p = q.front();
    q.pop();
    int xx = p.first, yy = p.second;
    if (xx == -1 || xx >= n - 1 || yy == -1 || yy >= m - 1) {
      cout << "INF" << '\n';
      ;
      return 0;
    }
    if (u[xx][yy]) continue;
    ans += (first[xx + 1] - first[xx]) * (second[yy + 1] - second[yy]);
    u[xx][yy] = true;
    if (!ngx[xx][yy]) q.push({xx, yy - 1});
    if (!ngx[xx][yy + 1]) q.push({xx, yy + 1});
    if (!ngy[xx][yy]) q.push({xx - 1, yy});
    if (!ngy[xx + 1][yy]) q.push({xx + 1, yy});
  }
  cout << ans << '\n';
  ;
}
