#include <bits/stdc++.h>
using namespace std;
template <typename T>
T Input() {
  T v;
  cin >> v;
  return v;
}
template <typename T>
vector<T> InputVector(int n) {
  vector<T> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  return v;
}
template <typename T>
void InputArray(T* begin, int n) {
  for (int i = 0; i < n; ++i) {
    cin >> begin[i];
  }
}
void DumpGrid(vector<vector<int>>& grid) {}
int main(int, const char**) {
  int n, m;
  cin >> n >> m;
  struct Point {
    int x;
    int y;
  };
  struct Line {
    int a;
    int b;
    int c;
  };
  set<int> xs, ys;
  vector<Line> vl(n), hl(m);
  for (int i = 0; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    xs.insert(c);
    ys.insert(a);
    ys.insert(b);
    vl[i] = {a, b, c};
  }
  for (int i = 0; i < m; ++i) {
    int d, e, f;
    cin >> d >> e >> f;
    xs.insert(e);
    xs.insert(f);
    ys.insert(d);
    hl[i] = {d, e, f};
  }
  xs.insert(0);
  ys.insert(0);
  map<int, int> xmap;
  map<int, int> rxmap;
  {
    auto itr = xs.begin();
    for (int i = 0; i < xs.size(); ++i) {
      xmap[*itr] = i;
      rxmap[i] = *itr;
      ++itr;
    }
  }
  map<int, int> ymap;
  map<int, int> rymap;
  {
    auto itr = ys.begin();
    for (int i = 0; i < ys.size(); ++i) {
      ymap[*itr] = i;
      rymap[i] = *itr;
      ++itr;
    }
  }
  vector<vector<int>> grid(ys.size() * 2, vector<int>(xs.size() * 2, 0));
  for (auto& l : vl) {
    auto x = xmap[l.c];
    auto y0 = ymap[l.a];
    auto y1 = ymap[l.b];
    for (int i = y0; i < y1; ++i) {
      grid[i * 2][x * 2] = 1;
      grid[i * 2 + 1][x * 2] = 1;
    }
    grid[y1 * 2][x * 2] = 1;
  }
  for (auto& l : hl) {
    auto y = ymap[l.a];
    auto x0 = xmap[l.b];
    auto x1 = xmap[l.c];
    for (int i = x0; i < x1; ++i) {
      grid[y * 2][i * 2] = 1;
      grid[y * 2][i * 2 + 1] = 1;
    }
    grid[y * 2][x1 * 2] = 1;
  }
  DumpGrid(grid);
  queue<Point> q;
  q.push({xmap[0] * 2, ymap[0] * 2});
  bool inf = false;
  int64_t area = 0;
  while (!q.empty()) {
    auto tp = q.front();
    q.pop();
    auto x = tp.x;
    auto y = tp.y;
    if (grid[y][x] != 0) {
      continue;
    }
    if (x == 0 || y == 0 || x == xs.size() * 2 - 1 || y == ys.size() * 2 - 1) {
      inf = true;
      break;
    }
    if (x % 2 == 1 && y % 2 == 1) {
      auto tx = x / 2;
      auto ty = y / 2;
      area += ((rxmap[tx] - rxmap[tx - 1]) * (rymap[ty] - rymap[ty - 1]));
    }
    grid[y][x] = 2;
    q.push({x + 1, y});
    q.push({x - 1, y});
    q.push({x, y + 1});
    q.push({x, y - 1});
    DumpGrid(grid);
  }
  if (inf) {
    cout << "INF" << endl;
  } else {
    cout << area << endl;
  }
  return 0;
}
