#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10 + 6;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
const int MAX_N = 2 * 1e6 + 5;
const int LG = 25;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
map<int, int> cx;
map<int, int> cy;
map<int, int> xc;
map<int, int> yc;
int movx[4] = {-1, 0, 1, 0};
int movy[4] = {0, 1, 0, -1};
int val[3100][3100];
bool vis[3100][3100];
long long ans = 0;
int l1, l2;
int bfs(int a, int b) {
  queue<pair<int, int> > pq;
  if (!vis[a + 1][b + 1]) ans += val[a + 1][b + 1];
  pq.push({a, b});
  pq.push({a + 1, b + 1});
  vis[a][b] = 1;
  vis[a][b + 1] = 1;
  vis[a + 1][b] = 1;
  vis[a + 1][b + 1] = 1;
  while (!pq.empty()) {
    pair<int, int> aux = pq.front();
    pq.pop();
    if (!vis[aux.first][aux.second]) ans += val[aux.first][aux.second];
    vis[aux.first][aux.second] = 1;
    for (int i = 0; i < 4; i++) {
      int x, y;
      x = aux.first + movx[i];
      y = aux.second + movy[i];
      if (x == l1 || y == l2 || x == 0 || y == 0) {
        return 0;
      }
      if (!vis[x][y]) {
        pq.push({x, y});
      }
    }
  }
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  int a, b, c;
  map<int, int> cx;
  map<int, int> cy;
  set<int> sx;
  set<int> sy;
  vector<pair<pair<int, int>, int> > vx;
  vector<pair<pair<int, int>, int> > vy;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    sy.insert(c);
    sx.insert(a);
    sx.insert(b);
    vx.push_back({{a, b}, c});
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    sx.insert(a);
    sy.insert(b);
    sy.insert(c);
    vy.push_back({{b, c}, a});
  }
  sx.insert(0);
  sy.insert(0);
  int cnt = 0;
  for (auto xd : sx) {
    cx[xd] = 2 * cnt;
    xc[2 * cnt] = xd;
    cnt++;
  }
  l1 = cnt;
  cnt = 0;
  for (auto xd : sy) {
    cy[xd] = 2 * cnt;
    yc[2 * cnt] = xd;
    cnt++;
  }
  l2 = cnt;
  for (int i = 0; i < 2 * l1 + 3; i++) {
    for (int j = 0; j < 2 * l2 + 3; j++) {
      if ((j & 1) && (i & 1)) {
        val[i][j] = (xc[j + 1] - xc[j - 1]) * (yc[i + 1] - yc[i - 1]);
      }
    }
  }
  l1 = 2 * l1 + 4;
  l2 = 2 * l2 + 4;
  for (auto xd : vx) {
    for (int i = cx[xd.first.first]; i <= cx[xd.first.second]; i++) {
      vis[i][cy[xd.second]] = 1;
    }
  }
  for (auto xd : vy) {
    for (int i = cy[xd.first.first]; i <= cy[xd.first.second]; i++) {
      vis[cx[xd.second]][i] = 1;
    }
  }
  if (bfs(cx[0], cy[0]))
    cout << ans << endl;
  else
    cout << "INF" << endl;
  return 0;
}
