#include <bits/stdc++.h>
using namespace std;
using lnt = long long;
using Real = long double;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
              dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr Real eps = 1e-9;
const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX / 10, BBIG = LLONG_MAX / 10;
template <class T>
inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <class T>
inline T LCM(T a, T b) {
  T c = GCD(a, b);
  a /= c;
  return a * b;
}
template <class T>
inline T nCr(T a, T b) {
  T i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= (a + 1 - i);
    r /= i;
  }
  return r;
}
template <class T>
inline T nHr(T a, T b) {
  return nCr(a + b - 1, b);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using pint = pair<int, int>;
using plnt = pair<lnt, lnt>;
using vint = vector<int>;
using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lnt N, M;
  cin >> N >> M;
  lnt A[1000], B[1000], C[1000], D[1000], E[1000], F[1000];
  map<lnt, lnt> tate, yoko;
  const lnt CST = 1e9 + 10000;
  tate[0] = yoko[0] = -1;
  tate[-CST] = yoko[-CST] = tate[CST] = yoko[CST] = -1;
  for (lnt i = 0; i < (N); ++i) {
    cin >> A[i] >> B[i] >> C[i];
    tate[A[i]] = -1;
    tate[B[i]] = -1;
    yoko[C[i]] = -1;
  }
  for (lnt i = 0; i < (M); ++i) {
    cin >> D[i] >> E[i] >> F[i];
    tate[D[i]] = -1;
    yoko[E[i]] = -1;
    yoko[F[i]] = -1;
  }
  lnt tmp = 0;
  lnt invtate[2010], invyoko[2010];
  for (auto& e : tate) {
    e.second = tmp;
    invtate[tmp] = e.first;
    tmp++;
  }
  tmp = 0;
  for (auto& e : yoko) {
    e.second = tmp;
    invyoko[tmp] = e.first;
    tmp++;
  }
  lnt tatesiz = tate.size(), yokosiz = yoko.size();
  lnt initx, inity;
  using area = pair<plnt, plnt>;
  vector<vector<area>> field(tatesiz - 1, vector<area>(yokosiz - 1));
  for (lnt i = 0; i < (tatesiz - 1); ++i) {
    for (lnt j = 0; j < (yokosiz - 1); ++j) {
      field[i][j] = {{invtate[i], invtate[i + 1]},
                     {invyoko[j], invyoko[j + 1]}};
      if (invtate[i] == 0 and invyoko[j] == 0) {
        initx = i;
        inity = j;
      }
    }
  }
  vector<vlnt> tateimos(yokosiz, vlnt(tatesiz - 1, 0));
  for (lnt i = 0; i < (N); ++i) {
    lnt up = tate[A[i]], down = tate[B[i]];
    lnt yy = yoko[C[i]];
    tateimos[yy][up]++;
    tateimos[yy][down]--;
  }
  for (lnt i = 0; i < (yokosiz); ++i)
    for (lnt j = (1); j < (tatesiz - 1); ++j) {
      tateimos[i][j] += tateimos[i][j - 1];
    }
  vector<vlnt> yokoimos(tatesiz, vlnt(yokosiz - 1, 0));
  for (lnt i = 0; i < (M); ++i) {
    lnt left = yoko[E[i]], right = yoko[F[i]];
    lnt xx = tate[D[i]];
    yokoimos[xx][left]++;
    yokoimos[xx][right]--;
  }
  for (lnt i = 0; i < (tatesiz); ++i)
    for (lnt j = (1); j < (yokosiz - 1); ++j) {
      yokoimos[i][j] += yokoimos[i][j - 1];
    }
  queue<plnt> que;
  que.push({initx, inity});
  vector<vector<bool>> visit(tatesiz - 1, vector<bool>(yokosiz - 1, 0));
  visit[initx][inity] = 1;
  lnt ans = 0;
  while (!que.empty()) {
    plnt p = que.front();
    que.pop();
    lnt posx = p.first, posy = p.second;
    if (posx == 0 or posx == tatesiz - 2 or posy == 0 or posy == yokosiz - 2) {
      cout << "INF" << '\n';
      return 0;
    }
    lnt S = field[posx][posy].first.second - field[posx][posy].first.first;
    S *= (field[posx][posy].second.second - field[posx][posy].second.first);
    ans += S;
    for (lnt i = 0; i < (4); ++i) {
      lnt nxx = posx + dx[i], nxy = posy + dy[i];
      if (visit[nxx][nxy]) continue;
      if (nxx < 0 or tatesiz - 1 <= nxx or nxy < 0 or yokosiz - 1 <= nxy)
        continue;
      if (posx == nxx) {
        lnt J = field[posx][posy].first.first;
        J = tate[J];
        if (nxy < posy and tateimos[posy][J]) continue;
        if (posy < nxy and tateimos[nxy][J]) continue;
      } else {
        lnt I = field[posx][posy].second.first;
        I = yoko[I];
        if (nxx < posx and yokoimos[posx][I]) continue;
        if (posx < nxx and yokoimos[nxx][I]) continue;
      }
      que.push({nxx, nxy});
      visit[nxx][nxy] = 1;
    }
  }
  cout << ans << '\n';
}
