#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
struct Ve {
  int x;
  int y0, y1;
};
struct Ho {
  int x0, x1;
  int y;
};
int N, M;
Ve V[1011];
Ho H[1011];
const int SIZE = 6011;
char F[SIZE][SIZE];
bool in(int y, int x) { return 0 <= y && y < SIZE && 0 <= x && x < SIZE; }
void MAIN() {
  scanf("%d%d", &N, &M);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    V[i].x = c;
    V[i].y0 = a;
    V[i].y1 = b;
  }
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    H[i].y = a;
    H[i].x0 = b;
    H[i].x1 = c;
  }
  vector<int> xs, ys;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    xs.push_back(V[i].x);
    ys.push_back(V[i].y0);
    ys.push_back(V[i].y1);
  }
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    xs.push_back(H[i].x0);
    xs.push_back(H[i].x1);
    ys.push_back(H[i].y);
  }
  xs.push_back(0);
  ys.push_back(0);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  sort(ys.begin(), ys.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  auto get_x = [&](int x) {
    int k = lower_bound(xs.begin(), xs.end(), x) - xs.begin();
    return k * 2;
  };
  auto get_y = [&](int y) {
    int k = lower_bound(ys.begin(), ys.end(), y) - ys.begin();
    return k * 2;
  };
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int x = get_x(V[i].x);
    int y0 = get_y(V[i].y0);
    int y1 = get_y(V[i].y1);
    if (y0 > y1) swap(y0, y1);
    for (int y = y0; y <= y1; y++) F[y][x] = 1;
  }
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    int x0 = get_x(H[i].x0);
    int x1 = get_x(H[i].x1);
    int y = get_y(H[i].y);
    if (x0 > x1) swap(x0, x1);
    for (int x = x0; x <= x1; x++) F[y][x] = 1;
  }
  int x = get_x(0);
  int y = get_y(0);
  vector<pair<int, int> > stk;
  stk.emplace_back(y, x);
  int ans = 0;
  F[y][x] = 2;
  while (!stk.empty()) {
    y = stk.back().first;
    x = stk.back().second;
    stk.pop_back();
    for (int d = 0, d_len = (8); d < d_len; ++d) {
      int yy = y + dy[d];
      int xx = x + dx[d];
      if (!in(yy, xx)) {
        ans = -1;
        goto END;
      }
      if (F[yy][xx] == 0) {
        F[yy][xx] = 2;
        if ((yy & 1) && (xx & 1)) ans++;
        stk.emplace_back(yy, xx);
      }
    }
  }
END:;
  if (ans == -1)
    puts("INF");
  else
    printf("%d\n", ans);
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
