#include <bits/stdc++.h>
using namespace std;
const int INF = 500 + 5;
const int N = 4000 + 5;
const long long oo = 1e18 + 5;
const long long mod = 998244353;
int n, m;
vector<int> xs, ys;
int ban[N][N][4];
int used[N][N];
int a[N], b[N], c[N], d[N], e[N], f[N];
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, 1, -1, 0};
void bfs(int x, int y) {
  queue<pair<int, int>> Q;
  Q.push({x, y});
  used[x][y] = 1;
  while (!Q.empty()) {
    int u = Q.front().first;
    int v = Q.front().second;
    Q.pop();
    for (int dir = 0; dir < 4; ++dir) {
      if (ban[u][v][dir]) continue;
      int new_u = u + dx[dir];
      int new_v = v + dy[dir];
      if (new_u >= 0 && new_u <= (int)xs.size() && new_v >= 0 &&
          new_v <= (int)ys.size()) {
        if (!used[new_u][new_v]) {
          used[new_u][new_v] = 1;
          Q.push({new_u, new_v});
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    xs.push_back(a[i]);
    xs.push_back(b[i]);
    ys.push_back(c[i]);
  }
  for (int i = 1; i <= m; ++i) {
    cin >> d[i] >> e[i] >> f[i];
    xs.push_back(d[i]);
    ys.push_back(e[i]);
    ys.push_back(f[i]);
  }
  sort((xs).begin(), (xs).end());
  sort((ys).begin(), (ys).end());
  xs.resize(unique((xs).begin(), (xs).end()) - xs.begin());
  ys.resize(unique((ys).begin(), (ys).end()) - ys.begin());
  for (int i = 1; i <= n; ++i) {
    int id_a = lower_bound((xs).begin(), (xs).end(), a[i]) - xs.begin();
    int id_b = lower_bound((xs).begin(), (xs).end(), b[i]) - xs.begin();
    int id_c = lower_bound((ys).begin(), (ys).end(), c[i]) - ys.begin();
    for (int j = id_a + 1; j <= id_b; ++j)
      ban[j][id_c][1] = 1, ban[j][id_c + 1][2] = 1;
  }
  for (int i = 1; i <= m; ++i) {
    int id_d = lower_bound((xs).begin(), (xs).end(), d[i]) - xs.begin();
    int id_e = lower_bound((ys).begin(), (ys).end(), e[i]) - ys.begin();
    int id_f = lower_bound((ys).begin(), (ys).end(), f[i]) - ys.begin();
    for (int j = id_e + 1; j <= id_f; ++j)
      ban[id_d][j][3] = 1, ban[id_d + 1][j][0] = 1;
  }
  int x = lower_bound((xs).begin(), (xs).end(), 0) - xs.begin();
  int y = lower_bound((ys).begin(), (ys).end(), 0) - ys.begin();
  bfs(x, y);
  for (int i = 0; i <= (int)xs.size(); ++i) {
    if (used[i][0] || used[i][(int)xs.size()]) {
      return cout << "INF", 0;
    }
  }
  for (int i = 0; i <= (int)ys.size(); ++i) {
    if (used[0][i] || used[(int)ys.size()][i]) {
      return cout << "INF", 0;
    }
  }
  long long ans = 0;
  for (int i = 1; i < (int)xs.size(); ++i) {
    for (int j = 1; j < (int)ys.size(); ++j) {
      if (used[i][j]) ans += 1ll * (xs[i] - xs[i - 1]) * (ys[j] - ys[j - 1]);
    }
  }
  cout << ans;
  return 0;
}
