#include <bits/stdc++.h>
using namespace std;
const int maxint = (int)1e10;
using ll = long long;
int main() {
  int N, M;
  map<pair<int, int>, int> slines;
  map<pair<int, int>, int> vlines;
  set<int> sideg;
  set<int> vatig;
  cin >> N >> M;
  int x, y, A;
  sideg.insert(maxint);
  sideg.insert(-maxint);
  vatig.insert(maxint);
  vatig.insert(-maxint);
  for (int i = 0; i < N; i++) {
    cin >> x >> y >> A;
    int &point1 = vlines[make_pair(A, x)];
    if (point1 < y) {
      point1 = y;
      sideg.insert(A);
      vatig.insert(x);
      vatig.insert(y);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> x >> y;
    int &point1 = slines[make_pair(x, A)];
    if (point1 < y) {
      point1 = y;
      sideg.insert(x);
      sideg.insert(y);
      vatig.insert(A);
    }
  }
  vector<vector<tuple<int, int, bool, bool>>> grid(0);
  for (int y : vatig) {
    vector<tuple<int, int, bool, bool>> temp;
    for (int x : sideg) {
      temp.push_back(make_tuple(x, y, false, false));
    }
    grid.push_back(temp);
  }
  int rex;
  int rey;
  for (int y = 0; y < vatig.size(); y++) {
    for (int x = 0; x < sideg.size(); x++) {
      auto &loca = grid.at(y).at(x);
      rex = get<0>(loca);
      rey = get<1>(loca);
      if (slines.count(make_pair(rex, rey))) {
        get<2>(loca) = true;
        int maxsecond = slines.at(make_pair(rex, rey));
        int next = 1;
        while (get<0>(grid.at(y).at(x + next)) < maxsecond) {
          get<2>(grid.at(y).at(x + next)) = true;
          next++;
        }
      }
      if (vlines.count(make_pair(rex, rey))) {
        get<3>(loca) = true;
        int maxsecond = vlines.at(make_pair(rex, rey));
        int next = 1;
        while (get<1>(grid.at(y + next).at(x)) < maxsecond) {
          get<3>(grid.at(y + next).at(x)) = true;
          next++;
        }
      }
    }
  }
  int minx;
  int miny;
  for (int i = 0; i < vatig.size(); i++) {
    if (get<1>(grid.at(i).at(0)) <= 0) {
      miny = i;
    } else {
      break;
    }
  }
  for (int j = 0; j < sideg.size(); j++) {
    if (get<0>(grid.at(0).at(j)) <= 0) {
      minx = j;
    } else {
      break;
    }
  }
  queue<pair<int, int>> Q;
  long long area = 0;
  vector<vector<bool>> fixed(vatig.size(), vector<bool>(sideg.size(), true));
  Q.push(make_pair(minx, miny));
  while (Q.size()) {
    minx = Q.front().first;
    miny = Q.front().second;
    if (minx == 0 || minx == (int)sideg.size() - 1) break;
    if (miny == 0 || miny == (int)vatig.size() - 1) break;
    auto loca = grid.at(miny).at(minx);
    area += (long long)(get<0>(grid[miny][minx + 1]) - get<0>(loca)) *
            (get<1>(grid[miny + 1][minx]) - get<1>(loca));
    fixed.at(miny).at(minx) = false;
    if (!get<2>(loca) && fixed.at(miny - 1).at(minx)) {
      Q.push(make_pair(miny - 1, minx));
    }
    if (!get<3>(loca) && fixed.at(miny).at(minx - 1)) {
      Q.push(make_pair(miny, minx - 1));
    }
    loca = grid.at(miny + 1).at(minx);
    if (!get<2>(loca) && fixed.at(miny + 1).at(minx)) {
      Q.push(make_pair(miny + 1, minx));
    }
    loca = grid.at(miny).at(minx + 1);
    if (!get<3>(loca) && fixed.at(miny).at(minx + 1)) {
      Q.push(make_pair(miny, minx + 1));
    }
    Q.pop();
  }
  if (!Q.size()) {
    cout << area - 1 << endl;
  } else {
    cout << "INF" << endl;
  }
}
