#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename C, typename T = decay<decltype(*begin(declval<C>()))>,
          typename enable_if<!is_same<C, string>::value>::type * = nullptr>
ostream &operator<<(ostream &os, const C &c) {
  bool f = true;
  os << "[";
  for (const auto &x : c) {
    if (!f) os << ", ";
    f = false;
    os << x;
  }
  return os << "]";
}
template <typename T>
void debug(string s, T x) {
  cerr << s << " = " << x << "\n";
}
template <typename T, typename... Args>
void debug(string s, T x, Args... args) {
  cerr << s.substr(0, s.find(',')) << " = " << x << " | ";
  debug(s.substr(s.find(',') + 2), args...);
}
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
bool connect[1005][1005][4], visited[1005][1005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<array<int, 3>> hori, vert;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    vert.push_back({c, a, b});
  }
  for (int i = 0; i < m; i++) {
    int d, e, f;
    cin >> d >> e >> f;
    hori.push_back({d, e, f});
  }
  sort(hori.begin(), hori.end());
  sort(vert.begin(), vert.end());
  int sr = -1, sc = -1;
  for (int i = 1; i < n; i++)
    for (int j = 1; j < m; j++) {
      if (vert[i - 1][1] > hori[j - 1][0] || vert[i - 1][2] < hori[j][0])
        connect[i][j][0] = true;
      if (hori[j][1] > vert[i - 1][0] || hori[j][2] < vert[i][0])
        connect[i][j][1] = true;
      if (vert[i][1] > hori[j - 1][0] || vert[i][2] < hori[j][0])
        connect[i][j][2] = true;
      if (hori[j - 1][1] > vert[i - 1][0] || hori[j - 1][2] < vert[i][0])
        connect[i][j][3] = true;
      if (vert[i - 1][0] < 0 && vert[i][0] >= 0 && hori[j - 1][0] < 0 &&
          hori[j][0] >= 0)
        sr = i, sc = j;
    }
  if (sr == -1) {
    cout << "INF\n";
    return 0;
  }
  long long ret = 0;
  queue<pair<int, int>> q;
  q.push({sr, sc});
  visited[sr][sc] = true;
  while (!q.empty()) {
    int r = q.front().first, c = q.front().second;
    q.pop();
    if (r == 0 || r == n || c == 0 || c == m) {
      cout << "INF\n";
      return 0;
    }
    ret += 1LL * (vert[r][0] - vert[r - 1][0]) * (hori[c][0] - hori[c - 1][0]);
    for (int i = 0; i < 4; i++)
      if (connect[r][c][i] && !visited[r + dr[i]][c + dc[i]]) {
        q.push({r + dr[i], c + dc[i]});
        visited[r + dr[i]][c + dc[i]] = true;
      }
  }
  cout << ret << "\n";
  return 0;
}
