#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T sgn(T a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
const double pi = acos(-1.0);
int n;
int m;
const int N = 3100;
char to[N][N][4], was[N][N];
int main() {
  vector<int> dx = {-1, 0, 1, 0};
  vector<int> dy = {0, 1, 0, -1};
  cin >> n >> m;
  vector<int> a(n), b(n), c(n);
  map<int, int> from_x, from_y;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    from_x[a[i]] = 0;
    from_x[b[i]] = 0;
    from_y[c[i]] = 0;
  }
  vector<int> d(m), e(m), f(m);
  for (int i = 0; i < m; i++) {
    cin >> d[i] >> e[i] >> f[i];
    from_x[d[i]] = 0;
    from_y[e[i]] = 0;
    from_y[f[i]] = 0;
  }
  from_x[0] = 0;
  from_y[0] = 0;
  vector<int> to_x(((int)(from_x).size())), to_y(((int)(from_y).size()));
  int kx = 1;
  for (auto& q : from_x) {
    q.second = kx;
    to_x[kx] = q.first;
    kx++;
  }
  int ky = 1;
  for (auto& q : from_y) {
    q.second = ky;
    to_y[ky] = q.first;
    ky++;
  }
  for (int i = 0; i < n; i++) {
    int xa = from_x[a[i]], xb = from_x[b[i]], yc = from_y[c[i]];
    for (int j = xa; j < xb; j++) {
      to[j][yc - 1][1] = -1;
      to[j][yc][3] = -1;
    }
  }
  for (int i = 0; i < m; i++) {
    int xd = from_x[d[i]], ye = from_y[e[i]], yf = from_y[f[i]];
    for (int j = ye; j < yf; j++) {
      to[xd][j][0] = -1;
      to[xd - 1][j][2] = -1;
    }
  }
  vector<pair<int, int> > q = {{from_x[0], from_y[0]}};
  long long ans = 0;
  was[q[0].first][q[0].second] = 1;
  for (int l = 0; l < ((int)(q).size()); l++) {
    pair<int, int> cur = q[l];
    int x = cur.first, y = cur.second;
    if (x == 0 || y == 0 || x == kx || y == ky) {
      cout << "INF" << endl;
      return 0;
    }
    ans += ((long long)to_x[x + 1] - to_x[x]) * (to_y[y + 1] - to_y[y]);
    for (int k = 0; k < 4; k++) {
      int xc = cur.first + dx[k], yc = cur.second + dy[k];
      if (to[x][y][k] != -1 && !was[xc][yc]) {
        q.push_back(make_pair(xc, yc));
        was[xc][yc] = 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
