#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

const int N = 3e3 + 10;
bool visit[N][N];
bitset<4> dir[N][N];

struct Seg {
  int L, R, pos;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<Seg> a(n), b(m);
  vector<int> X, Y;
  X.push_back(-INF); X.push_back(INF);
  Y.push_back(-INF); Y.push_back(INF);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].L >> a[i].R >> a[i].pos;
    X.push_back(a[i].L);
    X.push_back(a[i].R);
    Y.push_back(a[i].pos);
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i].pos >> b[i].L >> b[i].R;
    Y.push_back(b[i].L);
    Y.push_back(b[i].R);
    X.push_back(b[i].pos);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  sort(Y.begin(), Y.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());

  int sx = upper_bound(X.begin(), X.end(), 0) - X.begin() - 1;
  int sy = upper_bound(Y.begin(), Y.end(), 0) - Y.begin() - 1;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      for (int k = 0; k < 4; ++k) dir[i][j][k] = 1;
    }
  }

  for (int i = 0; i < n; ++i) {
    int u = lower_bound(X.begin(), X.end(), a[i].L) - X.begin();
    int v = lower_bound(X.begin(), X.end(), a[i].R) - X.begin();
    int w = lower_bound(Y.begin(), Y.end(), a[i].pos) - Y.begin();
    for (int x = u; x < v; ++x) {
      dir[x][w - 1][1] = dir[x][w][3] = 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    int u = lower_bound(Y.begin(), Y.end(), b[i].L) - Y.begin();
    int v = lower_bound(Y.begin(), Y.end(), b[i].R) - Y.begin();
    int w = lower_bound(X.begin(), X.end(), b[i].pos) - X.begin();
    for (int y = u; y < v; ++y) {
      dir[w - 1][y][0] = dir[w][y][2] = 0;
    }
  }
  int64 ret = 0;
  queue<ii> Q;
  Q.push({sx, sy});
  visit[sx][sy] = true;
  bool found = false;
  while (!Q.empty()) {
    int u = Q.front().first;
    int v = Q.front().second;
    // trace(u, v, X[u], X[u + 1], Y[v], Y[v + 1]);
    Q.pop();
    ret += 1LL * (X[u + 1] - X[u]) * (Y[v + 1] - Y[v]);
    for (int k = 0; k < 4; ++k) {
      if (!dir[u][v][k]) continue;
      int nu = u + d[k][0];
      int nv = v + d[k][1];
      if (nu < 0 || nu == X.size() - 1 || nv < 0 || nv >= Y.size() - 1) continue;
      if (nu == 0 || nv == 0 || nu == X.size() - 2 || nv == Y.size() - 2) found = true;
      if (visit[nu][nv]) continue;
      visit[nu][nv] = true;
      Q.push({nu, nv});
    }
  }
  if (found) {
    cout << "INF" << endl;
  } else {
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 82848