#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using vvint = vector<vint>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr long long DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr long long DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
long long gcd(long long a, long long b) {
  while (b) {
    swap(a %= b, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long sign(long long x) { return (x > 0) - (x < 0); }
template <typename T>
void fin(T mes) {
  cout << mes << endl;
  exit(0);
}
template <typename T, typename U>
bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T, typename U>
bool chmin(T &a, const U &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
  os << "(" << rhs.first << ", " << rhs.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &rhs) {
  os << "{";
  for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
    os << *itr << (next(itr) != rhs.end() ? ", " : "");
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &rhs) {
  os << "{";
  for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
    os << *itr << (next(itr) != rhs.end() ? ", " : "");
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &rhs) {
  os << "{";
  for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
    os << *itr << (next(itr) != rhs.end() ? ", " : "");
  }
  os << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &rhs) {
  os << "{";
  for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
    os << *itr << (next(itr) != rhs.end() ? ", " : "");
  }
  os << "}";
  return os;
}
struct setup {
  static constexpr long long PREC = 20;
  setup() {
    cout << fixed << setprecision(PREC);
    cerr << fixed << setprecision(PREC);
  };
} setup;
long long N, M;
long long A[1100], B[1100], C[1100];
long long D[1100], E[1100], F[1100];
long long wall[6600][6600];
vint py, px;
map<long long, long long> zaty, zatx;
void dfs(long long y, long long x) {
  stack<pint> stk;
  stk.emplace(y, x);
  while (!stk.empty()) {
    long long cy = stk.top().first, cx = stk.top().second;
    wall[cy][cx] = 1;
    stk.pop();
    for (long long i = 0; i < (long long)(4); i++) {
      long long ny = cy + DY[i], nx = cx + DX[i];
      if (ny < 0 || nx < 0 || ny >= 6600 || nx >= 6600 || wall[ny][nx]) {
        continue;
      }
      stk.emplace(ny, nx);
    }
  }
}
signed main() {
  cin >> N >> M;
  py.emplace_back(0), px.emplace_back(0);
  py.emplace_back(INT_MIN), px.emplace_back(INT_MIN);
  for (long long i = 0; i < (long long)(N); i++) {
    cin >> A[i] >> B[i] >> C[i];
    py.emplace_back(A[i]), py.emplace_back(B[i]), px.emplace_back(C[i]);
  }
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> D[i] >> E[i] >> F[i];
    py.emplace_back(D[i]), px.emplace_back(E[i]), px.emplace_back(F[i]);
  }
  sort((py).begin(), (py).end()),
      (py).erase(unique((py).begin(), (py).end()), (py).end());
  sort((px).begin(), (px).end()),
      (px).erase(unique((px).begin(), (px).end()), (px).end());
  for (long long i = 0; i < (long long)(py.size()); i++) {
    zaty[py[i]] = i;
  }
  for (long long i = 0; i < (long long)(px.size()); i++) {
    zatx[px[i]] = i;
  }
  for (long long i = 0; i < (long long)(N); i++) {
    long long y0 = zaty[A[i]] * 2, y1 = zaty[B[i]] * 2, x = zatx[C[i]] * 2;
    for (long long j = y0; j <= y1; j++) {
      wall[j][x] = 1;
    }
  }
  for (long long i = 0; i < (long long)(M); i++) {
    long long y = zaty[D[i]] * 2, x0 = zatx[E[i]] * 2, x1 = zatx[F[i]] * 2;
    for (long long j = x0; j <= x1; j++) {
      wall[y][j] = 1;
    }
  }
  dfs(zaty[0] * 2, zatx[0] * 2);
  if (wall[0][0] || wall[0][6600 - 1] || wall[6600 - 1][0] ||
      wall[6600 - 1][6600 - 1]) {
    fin("INF");
  }
  long long ans = 0;
  for (long long i = 0; i < (long long)(6600); i++) {
    for (long long j = 0; j < (long long)(6600); j++) {
      if ((i & 1) && (j & 1) && wall[i][j]) {
        ans += (py[i / 2 + 1] - py[i / 2]) * (px[i / 2 + 1] - px[i / 2]);
      }
    }
  }
  cout << ans << endl;
}
