#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 1000000001;
constexpr long long LINF = 1LL << 60;
constexpr long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void remove_duplication(vector<int>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
long long ans = 0;
int H, W;
bool wall[3030][3030][4], vis[3030][3030];
vector<int> h{0, INF, -INF}, w{0, INF, -INF};
void dfs(int i, int j) {
  if (i < 0 || j < 0 || i >= H || j >= W) return;
  if (vis[i][j]) return;
  vis[i][j] = true;
  ans += (h[i + 1] - h[i]) * (w[j + 1] - w[j]);
  if (wall[i][j][0] == false) dfs(i - 1, j);
  if (wall[i][j][1] == false) dfs(i + 1, j);
  if (wall[i][j][2] == false) dfs(i, j - 1);
  if (wall[i][j][3] == false) dfs(i, j + 1);
  return;
}
void Main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N), C(N), D(M), E(M), F(M);
  for (int i = (0); i < (N); ++i) {
    cin >> A[i] >> B[i] >> C[i];
    h.push_back(A[i]);
    h.push_back(B[i]);
    w.push_back(C[i]);
  }
  for (int i = (0); i < (M); ++i) {
    cin >> D[i] >> E[i] >> F[i];
    h.push_back(D[i]);
    w.push_back(E[i]);
    w.push_back(F[i]);
  }
  remove_duplication(h);
  remove_duplication(w);
  H = h.size();
  W = w.size();
  h.push_back(h.back() + 1);
  w.push_back(w.back() + 1);
  map<int, int> mh, mw;
  for (int i = (0); i < (H); ++i) mh[h[i]] = i;
  for (int i = (0); i < (W); ++i) mw[w[i]] = i;
  for (int i = (0); i < (N); ++i) {
    int x1 = mh[A[i]], x2 = mh[B[i]], y = mw[C[i]];
    for (int j = (x1); j < (x2); ++j) wall[j][y][2] = true;
    for (int j = (x1); j < (x2); ++j) wall[j][y - 1][3] = true;
  }
  for (int i = (0); i < (M); ++i) {
    int x = mh[D[i]], y1 = mw[E[i]], y2 = mw[F[i]];
    for (int j = (y1); j < (y2); ++j) wall[x][j][0] = true;
    for (int j = (y1); j < (y2); ++j) wall[x - 1][j][1] = true;
  }
  dfs(mh[0], mw[0]);
  bool flag = false;
  for (int i = (0); i < (H); ++i)
    if (vis[i][0] || vis[i][W - 1]) flag = true;
  for (int i = (0); i < (W); ++i)
    if (vis[0][i] || vis[H - 1][i]) flag = true;
  if (flag)
    cout << "INF"
         << "\n";
  else
    cout << ans << "\n";
  return;
}
int main(void) {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
