#include <bits/stdc++.h>
using namespace std;
template <class T>
class breadth_first_search_iterator {
 public:
  queue<pair<T, T>> todo;
  function<bool(T)> notvisited;
  function<void(T)> mark_visited;
  function<set<T>(T)> neighbors;
  breadth_first_search_iterator() {}
  breadth_first_search_iterator(T start, function<bool(T)> notv,
                                function<void(T)> mark_v,
                                function<set<T>(T)> neigh)
      : notvisited(notv),
        mark_visited(mark_v),
        neighbors(neigh),
        end_(false),
        current(start),
        prev(start) {
    todo.push(make_pair(start, start));
    operator++();
  }
  void operator++() {
    end_ = true;
    while (!todo.empty()) {
      current = todo.front().first;
      prev = todo.front().second;
      todo.pop();
      if (notvisited(current)) {
        mark_visited(current);
        for (const T x : neighbors(current)) {
          todo.push(make_pair(x, current));
        }
        end_ = false;
        break;
      }
    }
  }
  T operator*() { return current; }
  T previous() { return prev; }
  bool end() { return end_; }

 private:
  T current;
  T prev;
  bool end_;
};
int main() {
  cout.precision(17);
  long long modd = 1000 * 1000 * 1000 + 7;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  uniform_int_distribution<int> rand_gen(0, modd);
  long long infinit = 10000000000000000;
  int test_cases = 1;
  for (int t = (1); t < (1) + (test_cases); ++t) {
    int n;
    cin >> n;
    int m;
    cin >> m;
    map<long long, int> xcoord, ycoord;
    xcoord[0] = 0;
    ycoord[0] = 0;
    map<long long, vector<pair<long long, long long>>> hor_lines, vert_lines;
    for (int i = (0); i < (0) + (n); ++i) {
      long long a;
      cin >> a;
      long long b;
      cin >> b;
      long long c;
      cin >> c;
      xcoord[a] = 0;
      xcoord[b] = 0;
      ycoord[c] = 0;
      hor_lines[c].push_back(make_pair(a, b));
    }
    for (int i = (0); i < (0) + (m); ++i) {
      long long d;
      cin >> d;
      long long e;
      cin >> e;
      long long f;
      cin >> f;
      xcoord[d] = 0;
      ycoord[e] = 0;
      ycoord[f] = 0;
      vert_lines[d].push_back(make_pair(e, f));
    }
    vector<long long> dict_x, dict_y;
    for (auto p : xcoord) {
      dict_x.push_back(p.first);
    }
    for (auto p : ycoord) {
      dict_y.push_back(p.first);
    }
    for (int i = (0); i < (0) + (dict_x.size()); ++i) {
      xcoord[dict_x[i]] = i;
    }
    for (int i = (0); i < (0) + (dict_y.size()); ++i) {
      ycoord[dict_y[i]] = i;
    }
    set<pair<int, int>> visited;
    breadth_first_search_iterator<pair<int, int>> bfs(
        make_pair(xcoord[0], ycoord[0]),
        [&visited](pair<int, int> x) {
          return (!(visited.find((x)) != visited.end()));
        },
        [&visited](pair<int, int> x) { visited.insert(x); },
        [&hor_lines, &vert_lines, &dict_x, &dict_y](pair<int, int> point) {
          set<pair<int, int>> ret;
          bool can_go = true;
          if ((point.first >= 0) && (point.first < dict_x.size()) &&
              (point.second >= 0) && (point.second < dict_y.size())) {
            for (auto seg : vert_lines[dict_x[point.first]]) {
              if ((seg.first <= dict_y[point.second]) &&
                  (seg.second > dict_y[point.second])) {
                can_go = false;
                break;
              }
            }
          }
          if (can_go) {
            ret.insert(make_pair(point.first - 1, point.second));
          }
          can_go = true;
          if ((point.first >= 0) && (point.first < dict_x.size()) &&
              (point.second >= 0) && (point.second < dict_y.size())) {
            for (auto seg : hor_lines[dict_y[point.second]]) {
              if ((seg.first <= dict_x[point.first]) &&
                  (seg.second > dict_x[point.first])) {
                can_go = false;
                break;
              }
            }
          }
          if (can_go) {
            ret.insert(make_pair(point.first, point.second - 1));
          }
          can_go = true;
          if ((point.first + 1 >= 0) && (point.first + 1 < dict_x.size()) &&
              (point.second >= 0) && (point.second < dict_y.size())) {
            for (auto seg : vert_lines[dict_x[point.first + 1]]) {
              if ((seg.first <= dict_y[point.second]) &&
                  (seg.second > dict_y[point.second])) {
                can_go = false;
                break;
              }
            }
          }
          if (can_go) {
            ret.insert(make_pair(point.first + 1, point.second));
          }
          can_go = true;
          if ((point.first >= 0) && (point.first < dict_x.size()) &&
              (point.second + 1 >= 0) && (point.second + 1 < dict_y.size())) {
            for (auto seg : hor_lines[dict_y[point.second + 1]]) {
              if ((seg.first <= dict_x[point.first]) &&
                  (seg.second > dict_x[point.first])) {
                can_go = false;
                break;
              }
            }
          }
          if (can_go) {
            ret.insert(make_pair(point.first, point.second + 1));
          }
          return ret;
        });
    long long ret = 0;
    bool infin = false;
    while (!bfs.end()) {
      if ((*bfs).first < 0) {
        infin = true;
        break;
      }
      if ((*bfs).second < 0) {
        infin = true;
        break;
      }
      if ((*bfs).first + 1 >= dict_x.size()) {
        infin = true;
        break;
      }
      if ((*bfs).second + 1 >= dict_y.size()) {
        infin = true;
        break;
      }
      ret += (dict_x[(*bfs).first + 1] - dict_x[(*bfs).first]) *
             (dict_y[(*bfs).second + 1] - dict_y[(*bfs).second]);
      ++bfs;
    }
    if (infin) {
      cout << "INF" << endl;
    } else {
      cout << ret << endl;
    }
  }
  return 0;
}
