#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000100 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

template<typename T>
map<T, int> compress(vector<T> &vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  map<T, int> dict;
  for (int i = 0; i < vec.size(); i++) {
    dict[vec[i]] = i;
  }
  return dict;
}

int A[SIZE], B[SIZE], C[SIZE], D[SIZE], E[SIZE], F[SIZE];

int main() {
  int N, M;
  vector<int> vecx, vecy;

  scanf("%d%d", &N, &M);

  for (int i = 0; i < N; i++) {
    scanf("%d%d%d", A + i, B + i, C + i);
    vecy.push_back(A[i]);
    vecy.push_back(B[i]);
    vecx.push_back(C[i]);
  }

  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", D + i, E + i, F + i);
    vecy.push_back(D[i]);
    vecx.push_back(E[i]);
    vecx.push_back(F[i]);
  }

  vecx.push_back(-INF);
  vecx.push_back(INF);
  vecy.push_back(-INF);
  vecy.push_back(INF);

  auto dictX = compress(vecx);
  auto dictY = compress(vecy);

  int W = vecx.size() - 1;
  int H = vecy.size() - 1;

  vector<vector<int>> visited(H, vector<int>(W));
  queue<pair<int, int>> que;

  for (int i = 0; i < H; i++) {
    if (!(vecy[i] <= 0 && 0 <= vecy[i + 1])) continue;
    for (int j = 0; j < W; j++) {
      if (vecx[j] <= 0 && 0 <= vecx[j + 1]) {
        //visited[i][j] = true;
        que.push({i, j});
      }
    }
  }

  vector<vector<int>> bV(H + 1, vector<int>(W + 1)), bH(H + 1, vector<int>(W + 1));


  for (int i = 0; i < N; i++) {
    bV[dictY[A[i]]][dictX[C[i]]]++;
    bV[dictY[B[i]]][dictX[C[i]]]--;
  }
  for (int i = 0; i < M; i++) {
    bH[dictY[D[i]]][dictX[E[i]]]++;
    bH[dictY[D[i]]][dictX[F[i]]]--;
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      bH[i][j + 1] += bH[i][j];
      bV[i + 1][j] += bV[i][j];
    }
  }

  ll ans = 0;

  while (que.size()) {
    auto p = que.front();
    que.pop();
    int y = p.first;
    int x = p.second;

    if (visited[y][x]) continue;
    visited[y][x] = true;

    if (y == 0 || y == H - 1 || x == 0 || x == W - 1) {
      cout << "INF" << endl;
      return 0;
    }

    ans += (ll)(vecx[x + 1] - vecx[x]) * (vecy[y + 1] - vecy[y]);

    debug(vecx[x], vecy[y]);
    debug(vecx[x + 1], vecy[y + 1]);

    // >
    if (x + 1 < W && !bV[y][x + 1]) {
      que.push({y, x + 1});
    }

    // <
    if (0 <= x - 1 && !bV[y][x]) {
      que.push({y, x - 1});
    }

    // ^
    if (0 <= y - 1 && !bH[y][x]) {
      que.push({y - 1, x});
    }

    // v
    if (y + 1 < H && !bH[y + 1][x]) {
      que.push({y + 1, x});
    }
  }

  // for (int i = 0; i < W; i++) {
  //   for (int j = 0; j < H; j++) {
  //     printf("%c", visited[i][j] ? '#' : '_');
  //   }
  //   puts("");
  // }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 109664