#include <bits/stdc++.h>
using namespace std;
const int maxm = 2e3 + 23;
const int maxn = 2e5 + 35;
int a[maxm], b[maxm], c[maxm], d[maxm], e[maxm], f[maxm];
vector<int> first, second;
int D[maxm][maxm], U[maxm][maxm], L[maxm][maxm], R[maxm][maxm];
inline int getx(int val) {
  return lower_bound((first).begin(), (first).end(), val) - first.begin();
}
inline int gety(int val) {
  return lower_bound((second).begin(), (second).end(), val) - second.begin();
}
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool check(int fx, int fy) {
  return fx >= 0 && fx < (int)(first).size() && fy >= 0 &&
         fy < (int)(second).size();
}
int vis[maxm][maxm];
long long solve(int sx, int sy) {
  queue<pair<int, int> > q;
  q.push(pair<int, int>(sx, sy));
  vis[sx][sy] = 1;
  long long ans = 0;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    ans += 1ll * (first[now.first + 1] - first[now.first]) *
           (second[now.second + 1] - second[now.second]);
    for (int i = 0; i < 4; ++i) {
      if (i == 0 && U[now.first][now.second]) continue;
      if (i == 1 && D[now.first][now.second]) continue;
      if (i == 2 && R[now.first][now.second]) continue;
      if (i == 3 && L[now.first][now.second]) continue;
      int fx = now.first + dx[i], fy = now.second + dy[i];
      if (check(fx, fy)) {
        if (!vis[fx][fy]) {
          vis[fx][fy] = 1;
          q.push(pair<int, int>(fx, fy));
        }
      } else
        return -1;
    }
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d %d", a + i, b + i, c + i);
    first.push_back(a[i]);
    first.push_back(b[i]);
    second.push_back(c[i]);
  }
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", d + i, e + i, f + i);
    first.push_back(d[i]);
    second.push_back(e[i]);
    second.push_back(f[i]);
  }
  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 = 1; i <= n; ++i) {
    a[i] = getx(a[i]);
    b[i] = getx(b[i]);
    c[i] = gety(c[i]);
    for (int j = a[i]; j < b[i]; ++j) {
      U[j][c[i] - 1] = 1;
      D[j][c[i]] = 1;
    }
  }
  for (int i = 1; i <= m; ++i) {
    d[i] = getx(d[i]);
    e[i] = gety(e[i]);
    f[i] = gety(f[i]);
    for (int j = e[i]; j < f[i]; ++j) {
      L[d[i]][j] = 1;
      R[d[i] - 1][j] = 1;
    }
  }
  long long res = solve(getx(0), gety(0));
  if (res == -1)
    puts("INF");
  else
    cout << res << '\n';
  return 0;
}
