#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
long long nextLong() {
  long long x;
  scanf("%lld", &x);
  return x;
}
vector<int> normalize(const vector<long long> v) {
  const int N = v.size();
  vector<int> res(N);
  vector<pair<long long, int>> t(N);
  for (int i = 0, _n = (int)(N); i < _n; ++i) t[i] = {v[i], i};
  sort((t).begin(), (t).end());
  int r = 0;
  for (int i = 0, _n = (int)(N); i < _n; ++i) {
    r += (i > 0 && t[i - 1].first != t[i].first);
    res[t[i].second] = r;
  }
  return res;
}
vector<long long> bai(const vector<long long>& a) {
  vector<long long> res;
  for (int i = 0, _n = (int)(a.size()); i < _n; ++i) {
    res.push_back(a[i]);
    res.push_back(a[i]);
  }
  return res;
}
bool wall[3010][3010];
bool vis[3010][3010];
int main2() {
  memset(wall, (0), sizeof(wall));
  memset(vis, (0), sizeof(vis));
  int N = nextLong();
  int M = nextLong();
  const long long B = 1e9 + 10;
  vector<long long> xs({-B, 0, B}), ys({-B, 0, B});
  vector<int> tate, yoko;
  for (int i = 0, _n = (int)(N); i < _n; ++i) {
    int A = nextLong();
    int B = nextLong();
    int C = nextLong();
    tate.push_back(A);
    tate.push_back(B);
    tate.push_back(C);
    xs.push_back(A);
    xs.push_back(B);
    ys.push_back(C);
  }
  for (int i = 0, _n = (int)(M); i < _n; ++i) {
    int D = nextLong();
    int E = nextLong();
    int F = nextLong();
    yoko.push_back(D);
    yoko.push_back(E);
    yoko.push_back(F);
    xs.push_back(D);
    ys.push_back(E);
    ys.push_back(F);
  }
  sort((xs).begin(), (xs).end());
  xs.erase(unique((xs).begin(), (xs).end()), xs.end());
  sort((ys).begin(), (ys).end());
  ys.erase(unique((ys).begin(), (ys).end()), ys.end());
  xs = bai(xs);
  ys = bai(ys);
  const int X = xs.size();
  const int Y = ys.size();
  for (int i = 0, _n = (int)(N); i < _n; ++i) {
    int a =
        next(lower_bound((xs).begin(), (xs).end(), tate[i * 3])) - xs.begin();
    int b = next(lower_bound((xs).begin(), (xs).end(), tate[i * 3 + 1])) -
            xs.begin();
    int c = next(lower_bound((ys).begin(), (ys).end(), tate[i * 3 + 2])) -
            ys.begin();
    for (int x = a; x <= b; x++) wall[x][c] = true;
  }
  for (int i = 0, _n = (int)(M); i < _n; ++i) {
    int d =
        next(lower_bound((xs).begin(), (xs).end(), yoko[i * 3])) - xs.begin();
    int e = next(lower_bound((ys).begin(), (ys).end(), yoko[i * 3 + 1])) -
            ys.begin();
    int f = next(lower_bound((ys).begin(), (ys).end(), yoko[i * 3 + 2])) -
            ys.begin();
    for (int y = e; y <= f; y++) wall[d][y] = true;
  }
  queue<pair<int, int>> q;
  {
    int x = next(lower_bound((xs).begin(), (xs).end(), 0)) - xs.begin();
    int y = next(lower_bound((ys).begin(), (ys).end(), 0)) - ys.begin();
    q.push({x, y});
    vis[x][y] = true;
  }
  const int dx[] = {0, 1, 0, -1};
  const int dy[] = {1, 0, -1, 0};
  bool inf = false;
  long long ans = 0;
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    {
      if (x == 0 || y == 0) {
        inf = true;
        break;
      }
      ans += (xs[x] - xs[x - 1]) * (ys[y] - ys[y - 1]);
    }
    for (int i = 0, _n = (int)(4); i < _n; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (0 <= nx && nx < X && 0 <= ny && ny < Y && !wall[nx][ny] &&
          !vis[nx][ny]) {
        vis[nx][ny] = true;
        q.push({nx, ny});
      }
    }
  }
  if (inf) {
    cout << "INF" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
int main() {
  main2();
  return 0;
}
