#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
void ABC168F() {
  int N, M;
  cin >> N >> M;
  multimap<int, pair<int, int> > ABC;
  multimap<int, pair<int, int> > DEF;
  set<int> xGrid;
  xGrid.insert(-1000000007);
  xGrid.insert(1000000007);
  set<int> yGrid;
  yGrid.insert(-1000000007);
  yGrid.insert(1000000007);
  for (int i = 0; i < N; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    ABC.insert({c, {a, b}});
    xGrid.insert(a);
    xGrid.insert(b);
    yGrid.insert(c);
  }
  for (int i = 0; i < M; ++i) {
    int d, e, f;
    cin >> d >> e >> f;
    DEF.insert({d, {e, f}});
    xGrid.insert(d);
    yGrid.insert(e);
    yGrid.insert(f);
  }
  int n = xGrid.size();
  int m = yGrid.size();
  vi xVec(xGrid.begin(), xGrid.end());
  vi yVec(yGrid.begin(), yGrid.end());
  vvi xBry(n + 1, vi(m + 1));
  vvi yBry(n + 1, vi(m + 1));
  for (auto& x : ABC) {
    int i =
        distance(yVec.begin(), lower_bound(yVec.begin(), yVec.end(), x.first));
    int j = distance(xVec.begin(),
                     lower_bound(xVec.begin(), xVec.end(), x.second.first));
    int k = distance(xVec.begin(),
                     lower_bound(xVec.begin(), xVec.end(), x.second.second));
    for (int m = j; m < k; ++m) {
      yBry[m][i] = 1;
    }
  }
  for (auto& x : DEF) {
    int i =
        distance(xVec.begin(), lower_bound(xVec.begin(), xVec.end(), x.first));
    int j = distance(yVec.begin(),
                     lower_bound(yVec.begin(), yVec.end(), x.second.first));
    int k = distance(yVec.begin(),
                     lower_bound(yVec.begin(), yVec.end(), x.second.second));
    for (int m = j; m < k; ++m) {
      xBry[i][m] = 1;
    }
  }
  vvi grid(n, vi(m));
  vvi visit(n, vi(m));
  int ii =
      distance(xVec.cbegin(), upper_bound(xVec.cbegin(), xVec.cend(), 0)) - 1;
  int jj =
      distance(yVec.cbegin(), upper_bound(yVec.cbegin(), yVec.cend(), 0)) - 1;
  queue<pair<int, int> > qu;
  qu.push({ii, jj});
  visit[ii][jj] = 1;
  ll sum = 0;
  while (!qu.empty()) {
    auto p = qu.front();
    int i = p.first;
    int j = p.second;
    qu.pop();
    sum += (xVec[i + 1] - xVec[i]) * (xVec[j + 1] - xVec[j]);
    if (xBry[i + 1][j] == 0 && visit[i + 1][j] == 0) {
      if (i + 1 == n - 1) {
        cout << "INF" << endl;
        return;
      }
      visit[i + 1][j] = 1;
      qu.push({i + 1, j});
    }
    if (xBry[i][j] == 0 && visit[i - 1][j] == 0) {
      if (i - 1 == 0) {
        cout << "INF" << endl;
        return;
      }
      visit[i - 1][j] = 1;
      qu.push({i - 1, j});
    }
    if (yBry[i][j + 1] == 0 && visit[i][j + 1] == 0) {
      if (j + 1 == m - 1) {
        cout << "INF" << endl;
        return;
      }
      visit[i][j + 1] = 1;
      qu.push({i, j + 1});
    }
    if (yBry[i][j] == 0 && visit[i][j - 1] == 0) {
      if (j - 1 == 0) {
        cout << "INF" << endl;
        return;
      }
      visit[i][j - 1] = 1;
      qu.push({i, j - 1});
    }
  }
  cout << sum << endl;
}
int main() {
  ABC168F();
  return 0;
}
