#include <bits/stdc++.h>
using namespace std;
mt19937_64 llrand((int)chrono::steady_clock::now().time_since_epoch().count());
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 3e3 + 5;
int n, m;
int a, b, c;
bool visited[N][N];
map<pair<pair<int, int>, pair<int, int>>, bool> blocked;
vector<int> xs, ys;
vector<tuple<int, int, int>> ns, ms;
bool isInf;
long long area;
bool isOut(int x, int y) {
  if (x == -1 or y == ys.size() or !y or x == xs.size() - 1) return true;
  return false;
}
bool isVisited(int x, int y) {
  if (x < 0 or x >= xs.size()) return false;
  if (y < 0 or y >= ys.size()) return false;
  return visited[x][y];
}
void dfs(int x, int y) {
  if (isInf) return;
  if (isOut(x, y)) {
    isInf = true;
    return;
  }
  visited[x][y] = true;
  area += (xs[x + 1] - xs[x]) * (ys[y] - ys[y - 1]);
  if (!blocked[{{x, y}, {x + 1, y}}] and !isVisited(x, y + 1)) dfs(x, y + 1);
  if (!blocked[{{x, y - 1}, {x + 1, y - 1}}] and !isVisited(x, y - 1))
    dfs(x, y - 1);
  if (!blocked[{{x + 1, y}, {x + 1, y - 1}}] and !isVisited(x + 1, y))
    dfs(x + 1, y);
  if (!blocked[{{x, y}, {x, y - 1}}] and !isVisited(x - 1, y)) dfs(x - 1, y);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  xs.push_back(0);
  ys.push_back(0);
  while (n--) {
    cin >> a >> b >> c;
    ns.push_back({a, b, c});
    xs.push_back(a), xs.push_back(b), ys.push_back(c);
  }
  while (m--) {
    cin >> a >> b >> c;
    ms.push_back({a, b, c});
    xs.push_back(a), ys.push_back(b), ys.push_back(c);
  }
  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 = 0; i < ns.size(); i++) {
    int ai, bi, ci;
    tie(ai, bi, ci) = ns[i];
    int ci_pos = lower_bound(ys.begin(), ys.end(), ci) - ys.begin();
    int pos = lower_bound(xs.begin(), xs.end(), ai) - xs.begin();
    while (pos < xs.size() and xs[pos] <= bi) {
      if (pos + 1 != xs.size() and xs[pos] != bi) {
        blocked[{{pos, ci_pos}, {pos + 1, ci_pos}}] = true;
        blocked[{{pos + 1, ci_pos}, {pos, ci_pos}}] = true;
      }
      pos++;
    }
  }
  for (int i = 0; i < ms.size(); i++) {
    int dj, ej, fj;
    tie(dj, ej, fj) = ms[i];
    int dj_pos = lower_bound(xs.begin(), xs.end(), dj) - xs.begin();
    int pos = lower_bound(ys.begin(), ys.end(), ej) - ys.begin();
    while (pos < ys.size() and ys[pos] <= fj) {
      if (pos + 1 != ys.size() and ys[pos] != fj) {
        blocked[{{dj_pos, pos}, {dj_pos, pos + 1}}] = true;
        blocked[{{dj_pos, pos + 1}, {dj_pos, pos}}] = true;
      }
      pos++;
    }
  }
  int x = lower_bound(xs.begin(), xs.end(), 0) - xs.begin();
  int y = lower_bound(ys.begin(), ys.end(), 0) - ys.begin();
  dfs(x, y);
  if (isInf)
    cout << "INF\n";
  else
    cout << area << "\n";
}
