#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n], c[n], d[m], e[m], f[m];
  vector<int> u, v;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i] >> b[i] >> c[i];
    a[i] *= 2;
    b[i] *= 2;
    c[i] *= 2;
    u.push_back(a[i]);
    v.push_back(b[i]);
    v.push_back(c[i]);
  }
  for (int i = 0; i < (m); ++i) {
    cin >> d[i] >> e[i] >> f[i];
    d[i] *= 2;
    e[i] *= 2;
    f[i] *= 2;
    v.push_back(d[i]);
    u.push_back(e[i]);
    u.push_back(e[i]);
  }
  sort(u.begin(), u.end());
  u.erase(unique(u.begin(), u.end()), u.end());
  int num = u.size();
  u.push_back(u[0] - 1);
  for (int i = 0; i < (num); ++i) {
    u.push_back(u[i] + 1);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  num = v.size();
  v.push_back(v[0] - 1);
  for (int i = 0; i < (num); ++i) {
    v.push_back(v[i] + 1);
  }
  sort(u.begin(), u.end());
  sort(v.begin(), v.end());
  int h = u.size();
  int w = v.size();
  int g[h][w];
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) g[i][j] = 0;
  for (int i = 0; i < (n); ++i) {
    int x = lower_bound(u.begin(), u.end(), a[i]) - u.begin();
    int y1 = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
    int y2 = lower_bound(v.begin(), v.end(), c[i]) - v.begin();
    for (int j = y1; j < y2 + 1; ++j) g[x][j] = 1;
  }
  for (int i = 0; i < (m); ++i) {
    int y = lower_bound(v.begin(), v.end(), d[i]) - v.begin();
    int x1 = lower_bound(u.begin(), u.end(), e[i]) - u.begin();
    int x2 = lower_bound(u.begin(), u.end(), f[i]) - u.begin();
    for (int j = x1; j < x2 + 1; ++j) g[j][y] = 1;
  }
  int sx = lower_bound(u.begin(), u.end(), 0) - u.begin();
  if (u[sx] % 2 == 0) sx--;
  int sy = lower_bound(v.begin(), v.end(), 0) - v.begin();
  if (v[sy] % 2 == 0) sy--;
  g[sx][sy] = 2;
  if (sx == 0 || sx == h - 1 || sy == 0 || sy == w - 1) {
    cout << "INF" << endl;
    return 0;
  }
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  while (que.size() > 0) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    for (int i = 0; i < (4); ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx == 0 || nx == h - 1 || ny == 0 || ny == w - 1) {
        cout << "INF" << endl;
        return 0;
      }
      if (g[nx][ny] == 0) {
        g[nx][ny] = 2;
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (g[i][j] == 2 && i % 2 == 0 && j % 2 == 0) {
        long long int x1 = u[i - 1], x2 = u[i + 1];
        long long int y1 = v[j - 1], y2 = v[j + 1];
        ans += (x2 - x1) / 2 * (y2 - y1) / 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
