#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
struct Segment {
  int a, b, c;
};
using Segments = vector<Segment>;
istream &operator>>(istream &is, Segment &s) { return is >> s.a >> s.b >> s.c; }
tuple<int, int, int, int> compress(Segments &X, Segments &Y, vector<int> &dX,
                                   vector<int> &dY) {
  vector<int> xs, ys;
  xs.push_back(0);
  ys.push_back(0);
  for (auto e : X) {
    for (int i = (int)(-1); i <= (int)(1); i++) {
      xs.push_back(e.a + i);
      xs.push_back(e.b + i);
      ys.push_back(e.c + i);
    }
  }
  for (auto e : Y) {
    for (int i = (int)(-1); i <= (int)(1); i++) {
      xs.push_back(e.a + i);
      ys.push_back(e.b + i);
      ys.push_back(e.c + i);
    }
  }
  sort((xs.begin()), (xs.end()));
  sort((ys.begin()), (ys.end()));
  xs.erase(unique((xs.begin()), (xs.end())), xs.end());
  ys.erase(unique((ys.begin()), (ys.end())), ys.end());
  for (int i = 0; i < (int)(xs.size() - 1); i++)
    dX.push_back(xs[i + 1] - xs[i]);
  for (int i = 0; i < (int)(ys.size() - 1); i++)
    dY.push_back(ys[i + 1] - ys[i]);
  for (auto &e : X) {
    e.a = find((xs.begin()), (xs.end()), e.a) - xs.begin();
    e.b = find((xs.begin()), (xs.end()), e.b) - xs.begin();
    e.c = find((ys.begin()), (ys.end()), e.c) - ys.begin();
  }
  for (auto &e : Y) {
    e.a = find((xs.begin()), (xs.end()), e.a) - xs.begin();
    e.b = find((ys.begin()), (ys.end()), e.b) - ys.begin();
    e.c = find((ys.begin()), (ys.end()), e.c) - ys.begin();
  }
  int sx = find((xs.begin()), (xs.end()), 0) - xs.begin();
  int sy = find((ys.begin()), (ys.end()), 0) - ys.begin();
  return {xs.size(), ys.size(), sx, sy};
}
template <typename T>
long long gBFS(int si, int sj, vector<T> &field) {
  long long ret = 0;
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  int h = field.size();
  int w = field[0].size();
  using P = pair<int, int>;
  queue<P> que;
  que.emplace(si, sj);
  vector<vector<bool> > used(h, vector<bool>(w, false));
  used[si][sj] = true;
  while (que.size()) {
    int x, y;
    tie(y, x) = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int tx = x + dx[i];
      int ty = y + dy[i];
      if (!(0 <= tx && tx < w && 0 <= ty && ty < h)) {
        return -1;
      }
      if (used[ty][tx]) continue;
      if (field[ty][tx] == -1) continue;
      used[ty][tx] = true;
      ret += field[ty][tx];
      que.emplace(ty, tx);
    }
  }
  return ret;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  Segments X(N), Y(M);
  vector<int> dX, dY;
  for (int i = 0; i < (int)(N); i++) cin >> X[i];
  for (int i = 0; i < (int)(M); i++) cin >> Y[i];
  auto [H, W, sx, sy] = compress(X, Y, dX, dY);
  assert(H <= 3001);
  assert(W <= 3001);
  vector<vector<long long> > f(2 * H - 1, vector<long long>(2 * W - 1));
  for (auto e : X) {
    for (int i = (int)(e.a * 2); i <= (int)(e.b * 2); i++) {
      f[i][e.c * 2] = -1;
    }
  }
  for (auto e : Y) {
    for (int j = (int)(e.b * 2); j <= (int)(e.c * 2); j++) {
      f[e.a * 2][j] = -1;
    }
  }
  for (int i = 0; i < (int)(H - 1); i++)
    for (int j = 0; j < (int)(W - 1); j++) {
      f[i * 2 + 1][j * 2 + 1] = (long long)dX[i] * dY[j];
    }
  int ans = -1;
  if (ans != -1) {
    cout << ans << endl;
  } else {
    cout << "INF\n";
  }
  return 0;
}
