#include <bits/stdc++.h>

struct Coord {
  int x, y;
};

std::ostream& operator<<(std::ostream& os, const Coord& c) {
  os << "{" << c.x << "," << c.y << "}";
  return os;
}

template <typename State>
class BoundGrid {
 public:
  BoundGrid(int x, int y) : grid_(x * 2 + 1, std::vector(y * 2 + 1, State())) {}
  bool InBounds(const Coord& c) const {
    std::size_t x = coord(c.x), y = coord(c.y);
    return 0 <= x && x < grid_.size() && 0 <= y && y < grid_[0].size();
  }
  State& StateOf(const Coord& c) { return grid_[coord(c.x)][coord(c.y)]; }
  State& Boundary(const Coord& c, int dx, int dy) {
    return grid_[coord(c.x) + dx][coord(c.y) + dy];
  }
  void Debug(std::ostream& os,
             char to_char(const State& s, std::optional<char> boundary)) const {
    auto is_boundary = [](int x) -> bool { return x % 2 == 0; };

    // Print horizontal legend.
    os << "  ";  // Padding for the vertical legend.
    for (std::size_t y = 0; y < grid_[0].size(); ++y) {
      if (is_boundary(y)) {
        os << " ";
      } else {
        os << (y / 2) % 10;
      }
    }
    os << std::endl;

    for (std::size_t x = 0; x < grid_.size(); ++x) {
      // Print vertical legend.
      if (is_boundary(x)) {
        os << "  ";
      } else {
        os << (x / 2) % 10 << " ";
      }

      for (std::size_t y = 0; y < grid_[x].size(); ++y) {
        if (is_boundary(x) && is_boundary(y)) {
          os << "+";
          continue;
        }
        std::optional<char> boundary;
        if (is_boundary(x)) {
          boundary = '-';
        } else if (is_boundary(y)) {
          boundary = '|';
        }
        os << to_char(grid_[x][y], boundary);
      }
      os << std::endl;
    }
  }

 private:
  static std::size_t coord(std::size_t i) { return i * 2 + 1; }

  std::vector<std::vector<State>> grid_;
};

template <typename T>
std::vector<T> Compress(std::vector<T> v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
  return v;
}

template <typename T>
T Uncompress(const std::vector<T>& v, T x) {
  return std::lower_bound(v.begin(), v.end(), x) - v.begin();
}

template <typename T>
std::function<T(T)> Uncompressor(const std::vector<T>& v) {
  return [&v](T i) -> T { return Uncompress(v, i); };
}

#if DEBUG
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

const int kMax = 1000;
int A[kMax];
int B[kMax];
int C[kMax];
int D[kMax];
int E[kMax];
int F[kMax];

struct GridState {
  bool online;
  bool visited;
};

using Grid = BoundGrid<GridState>;

void DrawLineX(Grid& g, int x1, int x2, int y) {
  if (x1 > x2) swap(x1, x2);
  for (int x = x1; x < x2; ++x) {
    g.Boundary({x, y}, 0, -1).online = true;
  }
}

void DrawLineY(Grid& g, int x, int y1, int y2) {
  if (y1 > y2) swap(y1, y2);
  for (int y = y1; y < y2; ++y) {
    g.Boundary({x, y}, -1, 0).online = true;
  }
}

int main() {
  rd(int, N, M);

  rep(i, N) cin >> A[i] >> B[i] >> C[i];
  rep(i, M) cin >> D[i] >> E[i] >> F[i];

  set<int> xs;
  set<int> ys;

  xs.insert(A, A + N);
  xs.insert(B, B + N);
  ys.insert(C, C + N);
  xs.insert(D, D + M);
  ys.insert(E, E + M);
  ys.insert(F, F + M);

  xs.insert(0);
  xs.insert(*xs.begin() - 1);
  xs.insert(*xs.rbegin() + 1);
  ys.insert(0);
  ys.insert(*ys.begin() - 1);
  ys.insert(*ys.rbegin() + 1);

  vector cx = Compress(vector(all(xs)));
  vector cy = Compress(vector(all(ys)));
  auto xi = Uncompressor(cx);
  auto yi = Uncompressor(cy);

  Grid grid(cx.size() - 1, cy.size() - 1);

  rep(i, N) DrawLineX(grid, xi(A[i]), xi(B[i]), yi(C[i]));
  rep(i, M) DrawLineY(grid, xi(D[i]), yi(E[i]), yi(F[i]));

  Coord init = {xi(0), yi(0)};

  queue<Coord> que;
  que.push(init);

  grid.StateOf(init).visited = true;

  long long ans = 0;
  while (!que.empty()) {
    Coord here = que.front();
    que.pop();
    long long x = cx[here.x + 1] - cx[here.x];
    long long y = cy[here.y + 1] - cy[here.y];
    ans += x * y;
    rep(i, 4) {
      int dx[] = {0, 1, 0, -1};
      int dy[] = {1, 0, -1, 0};
      if (grid.Boundary(here, dx[i], dy[i]).online) {
        continue;
      }
      Coord there = {here.x + dx[i], here.y + dy[i]};
      if (!grid.InBounds(there)) {
        cout << "INF" << endl;
        return 0;
      }
      GridState& s = grid.StateOf(there);
      if (s.visited) {
        continue;
      }
      s.visited = true;
      que.push(there);
    }
  }
  wt(ans);
}


Measured memory_bytes: 74212