#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int> > > line[2];
  vector<int> grid[2];
  int idx, s, e, k;
  for (int i = 0; i < (2); i++) {
    k = i ? m : n;
    for (int j = 0; j < (k); j++) {
      if (i) {
        cin >> idx >> s >> e;
      } else {
        cin >> s >> e >> idx;
      }
      grid[i].push_back(idx);
      line[i].emplace_back(idx, pair<int, int>(s, e));
    }
  }
  int sz[2];
  for (int i = 0; i < (2); i++) {
    grid[i].push_back(0);
    sort(grid[i].begin(), grid[i].end());
    grid[i].erase(unique(grid[i].begin(), grid[i].end()), grid[i].end());
    sz[i] = grid[i].size();
  }
  vector<vector<int> > area(sz[0] * 2, vector<int>(sz[1] * 2, 0));
  for (int i = 0; i < (2); i++) {
    for (auto l : line[i]) {
      auto itr = lower_bound(grid[i].begin(), grid[i].end(), l.first);
      int li = distance(grid[i].begin(), itr);
      itr = lower_bound(grid[!i].begin(), grid[!i].end(), l.second.first);
      int d1 = distance(grid[!i].begin(), itr);
      itr = lower_bound(grid[!i].begin(), grid[!i].end(), l.second.second + 1);
      int d2 = distance(grid[!i].begin(), itr);
      for (int j = 0; j < ((d2 - d1) * 2 - 1); j++) {
        int idx1 = li * 2;
        int idx2 = d1 * 2 + j;
        if (i) swap(idx1, idx2);
        area[idx1][idx2] = 1;
      }
    }
  }
  int st[2];
  for (int i = 0; i < (2); i++) {
    auto itr = lower_bound(grid[i].begin(), grid[i].end(), 0);
    st[i] = distance(grid[i].begin(), itr) * 2;
  }
  long long ans = 0;
  queue<pair<int, int> > q;
  q.emplace(st[0], st[1]);
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if (area[x][y]) continue;
    if (x == 0 || y == 0 || x >= (sz[0] - 1) * 2 || y >= (sz[1] - 1) * 2) {
      cout << "INF" << endl;
      return 0;
    }
    if (x % 2 && y % 2) {
      ans += (grid[0][x / 2 + 1] - grid[0][x / 2]) *
             (grid[1][y / 2 + 1] - grid[1][y / 2]);
    }
    for (int i = 0; i < (4); i++) {
      int nx = x;
      int ny = y;
      int dir = (i % 2) ? 1 : -1;
      if (i / 2)
        nx += dir;
      else
        ny += dir;
      if (!area[nx][ny]) q.emplace(nx, ny);
    }
    area[x][y] = 1;
  }
  cout << ans << endl;
  return 0;
}
