#include <bits/stdc++.h>
using namespace std;
const int N = 4e3 + 100;
const int inf = 2e9;
const long long inf2 = 5e18;
int fx[] = {0, 0, -1, 1};
int fy[] = {1, -1, 0, 0};
bool gfo[N * N][4];
bool vst[N][N];
long long area[N * N];
int n, m;
int trans(int i, int j) { return m * i + j; }
long long sum(long long a, long long b) {
  if (a == inf2 || b == inf2) return inf2;
  return a + b;
}
void dfs(int y, int x, long long &A) {
  vst[y][x] = true;
  A = sum(A, area[trans(y, x)]);
  for (int c = int(0); c < int(4); ++c)
    if (gfo[trans(y, x)][c]) {
      int yy = y + fy[c];
      int xx = x + fx[c];
      if (xx < 0 || xx >= m) continue;
      if (yy < 0 || yy >= n) continue;
      if (vst[yy][xx]) continue;
      dfs(yy, xx, A);
    }
}
int main() {
  cin >> n >> m;
  set<int> X, Y;
  X.insert(inf);
  X.insert(-inf);
  Y.insert(inf);
  Y.insert(-inf);
  vector<pair<int, int> > LH, LV;
  for (int i = int(0); i < int(n); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    X.insert(c);
    Y.insert(a);
    Y.insert(b);
    LV.push_back({c, a});
    LV.push_back({c, b});
  }
  for (int i = int(0); i < int(m); ++i) {
    int d, e, f;
    cin >> d >> e >> f;
    if (e > f) swap(e, f);
    X.insert(e);
    X.insert(f);
    Y.insert(d);
    LH.push_back({e, d});
    LH.push_back({f, d});
  }
  vector<long long> XX, YY;
  for (int x : X) XX.push_back(x);
  for (int y : Y) YY.push_back(y);
  n = int((Y).size()) - 1, m = int((X).size()) - 1;
  for (int i = int(0); i < int(int((YY).size()) - 1); ++i)
    for (int j = int(0); j < int(int((XX).size()) - 1); ++j) {
      if (XX[j] == inf || XX[j] == -inf || XX[j + 1] == inf ||
          XX[j + 1] == -inf || YY[i] == inf || YY[i] == -inf ||
          YY[i + 1] == inf || YY[i + 1] == -inf)
        area[trans(i, j)] = inf2;
      else
        area[trans(i, j)] = (YY[i + 1] - YY[i]) * (XX[j + 1] - XX[j]);
    }
  for (int i = int(0); i < int(int((YY).size()) - 1); ++i)
    for (int j = int(0); j < int(int((XX).size()) - 1); ++j) {
      for (int c = int(0); c < int(4); ++c) gfo[trans(i, j)][c] = true;
      if (i == 0) gfo[trans(i, j)][1] = false;
      if (i == int((YY).size()) - 2) gfo[trans(i, j)][0] = false;
      if (j == 0) gfo[trans(i, j)][3] = false;
      if (j == int((XX).size()) - 2) gfo[trans(i, j)][2] = false;
    }
  for (int i = 0; i < int((LH).size()); i += 2) {
    int pos = lower_bound((YY).begin(), (YY).end(), LH[i].second) - YY.begin();
    for (int j = int(0); j < int(int((XX).size())); ++j)
      if (XX[j] >= LH[i].first && XX[j] < LH[i + 1].first) {
        gfo[trans(pos - 1, j)][0] = false;
        gfo[trans(pos, j)][1] = false;
      }
  }
  for (int i = 0; i < int((LV).size()); i += 2) {
    int pos = lower_bound((XX).begin(), (XX).end(), LV[i].first) - XX.begin();
    for (int j = int(0); j < int(int((YY).size())); ++j)
      if (YY[j] >= LV[i].second && YY[j] < LV[i + 1].second) {
        gfo[trans(j, pos - 1)][3] = false;
        gfo[trans(j, pos)][2] = false;
      }
  }
  int iniy = upper_bound((YY).begin(), (YY).end(), 0) - YY.begin();
  int inix = upper_bound((XX).begin(), (XX).end(), 0) - XX.begin();
  iniy--, inix--;
  long long A = 0;
  dfs(iniy, inix, A);
  if (A != inf2)
    cout << A << endl;
  else
    cout << "INF" << endl;
  return 0;
}
