#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(3));
  vector<vector<int>> B(N, vector<int>(3));
  for (auto& a : A)
    for (auto& x : a) cin >> x;
  for (auto& a : B)
    for (auto& x : a) cin >> x;
  map<int, int> xs, ys;
  xs[0] = 0;
  ys[0] = 0;
  for (auto a : A) {
    xs[a[0]] = 0;
    xs[a[1]] = 0;
    ys[a[2]] = 0;
  }
  for (auto a : B) {
    xs[a[0]] = 0;
    ys[a[1]] = 0;
    ys[a[2]] = 0;
  }
  vector<int> xp, yp;
  {
    int c = 0;
    for (auto& p : xs) {
      xp.push_back(p.first);
      p.second = c++;
    }
  }
  {
    int c = 0;
    for (auto& p : ys) {
      yp.push_back(p.first);
      p.second = c++;
    }
  }
  int nx = xs.size() - 1;
  int ny = ys.size() - 1;
  vector<vector<int>> b(nx + 2, vector<int>(ny + 2));
  for (auto a : A) {
    int x1 = xs[a[0]];
    int x2 = xs[a[1]];
    int y = ys[a[2]];
    for (int x = x1; x < x2; ++x) {
      b[x + 1][y] |= 1;
      b[x + 1][y + 1] |= 2;
    }
  }
  for (auto a : B) {
    int x = xs[a[0]];
    int y1 = ys[a[1]];
    int y2 = ys[a[2]];
    for (int y = y1; y < y2; ++y) {
      b[x][y + 1] |= 4;
      b[x + 1][y + 1] |= 8;
    }
  }
  vector<vector<bool>> painted(nx + 2, vector<bool>(ny + 2));
  queue<pair<int, int>> Q;
  {
    int x0 = xs[0];
    int y0 = ys[0];
    for (int i = 0; i <= 1; ++i)
      for (int j = 0; j <= 1; ++j) {
        int x = x0 + i;
        int y = y0 + j;
        painted[x][y] = true;
        Q.push({x, y});
      }
  }
  const int dx[] = {0, 0, +1, -1};
  const int dy[] = {+1, -1, 0, 0};
  while (!Q.empty()) {
    int x = Q.front().first;
    int y = Q.front().second;
    Q.pop();
    for (int k = 0; k < 4; ++k)
      if (!((b[x][y] >> k) & 1)) {
        int xx = x + dx[k];
        int yy = y + dy[k];
        if (xx == 0 || xx == nx + 1 || yy == 0 || yy == ny + 1) {
          cout << "INF" << endl;
          return 0;
        }
        if (!painted[xx][yy]) {
          painted[xx][yy] = true;
          Q.push({xx, yy});
        }
      }
  }
  long long res = 0;
  for (int x = 0; x < nx; ++x)
    for (int y = 0; y < ny; ++y)
      if (painted[x + 1][y + 1]) {
        long long xx = xp[x + 1] - xp[x];
        long long yy = yp[y + 1] - yp[y];
        res += xx * yy;
      }
  cout << res << endl;
}
