#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) {
      *this << ((it != d.b) ? ", " : "") << *it;
    }
    return *this << "]";
  }
};
const int inf = 1e9 + 1;
const int nax = 4 * 1010;
bool vis[nax][nax];
bool edge[nax][nax][4];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int, pair<int, int>>> pion(n), poz(m);
  vector<long long> rows, cols;
  rows.push_back(-inf);
  rows.push_back(inf);
  cols.push_back(-inf);
  cols.push_back(inf);
  for (int i = (0); i < (n); ++i) {
    scanf("%d %d %d", &pion[i].second.first, &pion[i].second.second,
          &pion[i].first);
    cols.push_back(pion[i].first);
    rows.push_back(pion[i].second.first);
    rows.push_back(pion[i].second.second);
  }
  for (int i = (0); i < (m); ++i) {
    scanf("%d %d %d", &poz[i].first, &poz[i].second.first,
          &poz[i].second.second);
    rows.push_back(poz[i].first);
    cols.push_back(poz[i].second.first);
    cols.push_back(poz[i].second.second);
  }
  sort(rows.begin(), rows.end());
  sort(cols.begin(), cols.end());
  rows.resize(unique(rows.begin(), rows.end()) - rows.begin());
  cols.resize(unique(cols.begin(), cols.end()) - cols.begin());
  int nn = rows.size();
  int mm = cols.size();
  for (int i = (0); i < (nn); ++i) {
    for (int j = (0); j < (mm); ++j) {
      for (int dir = (0); dir < (4); ++dir) {
        int ni = i + dx[dir], nj = j + dy[dir];
        if (ni < 0 || ni >= nn || nj < 0 || nj >= mm) {
          continue;
        }
        edge[i][j][dir] = true;
      }
    }
  }
  for (int i = (0); i < (n); ++i) {
    int col =
        lower_bound(cols.begin(), cols.end(), pion[i].first) - cols.begin();
    int lower_row =
        lower_bound(rows.begin(), rows.end(), pion[i].second.first) -
        rows.begin();
    int upper_row =
        lower_bound(rows.begin(), rows.end(), pion[i].second.second) -
        rows.begin();
    for (int row = (lower_row); row < (upper_row); ++row) {
      edge[row][col][1] = false;
      edge[row][col - 1][0] = false;
    }
  }
  for (int i = (0); i < (m); ++i) {
    int row =
        lower_bound(rows.begin(), rows.end(), poz[i].first) - rows.begin();
    int lower_col = lower_bound(cols.begin(), cols.end(), poz[i].second.first) -
                    cols.begin();
    int upper_col =
        lower_bound(cols.begin(), cols.end(), poz[i].second.second) -
        cols.begin();
    for (int col = (lower_col); col < (upper_col); ++col) {
      edge[row][col][3] = false;
      edge[row - 1][col][2] = false;
    }
  }
  int srow = lower_bound(rows.begin(), rows.end(), 0) - rows.begin();
  int scol = lower_bound(cols.begin(), cols.end(), 0) - cols.begin();
  queue<pair<int, int>> q;
  q.push({srow, scol});
  vis[srow][scol] = true;
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    for (int i = (0); i < (4); ++i) {
      if (!edge[cur.first][cur.second][i]) {
        continue;
      }
      int nx = cur.first + dx[i], ny = cur.second + dy[i];
      if (!vis[nx][ny]) {
        q.push({nx, ny});
        vis[nx][ny] = true;
      }
    }
  }
  for (int row = (0); row < (((int)((rows).size()))); ++row) {
    if (vis[row][0] || vis[row][((int)((cols).size())) - 1]) {
      cout << "INF\n";
      return 0;
    }
  }
  for (int col = (0); col < (((int)((cols).size()))); ++col) {
    if (vis[0][col] || vis[((int)((rows).size())) - 1][col]) {
      cout << "INF\n";
      return 0;
    }
  }
  long long res = 0;
  for (int row = (1); row < (((int)((rows).size())) - 1); ++row) {
    for (int col = (1); col < (((int)((cols).size())) - 1); ++col) {
      if (vis[row][col]) {
        long long kw =
            (rows[row + 1] - rows[row]) * (cols[col + 1] - cols[col]);
        res += kw;
      }
    }
  }
  cout << res << endl;
}
