INF   = 1_000_000_001i64
UP    =                1
RIGHT =                2
DOWN  =                4
LEFT  =                8

n, m = read_line.split.map(&.to_i)
ys = [-INF, 0i64, INF]
xs = [-INF, 0i64, INF]
vert = Array.new(n) do
  a, b, c = read_line.split.map(&.to_i64)
  ys << c
  xs << a << b
  {a, b, c}
end
horz = Array.new(m) do
  d, e, f = read_line.split.map(&.to_i64)
  xs << d
  ys << e << f
  {e, f, d}
end
ys = ys.uniq.sort
xs = xs.uniq.sort
# puts ys
# puts xs
wall = Array.new(ys.size) { Array.new(xs.size, 0) }
visited = Array.new(ys.size) { Array.new(xs.size, false) }
n.times do |i|
  x1 = xs.bsearch_index { |v, j| v >= vert[i][0] }.not_nil!
  x2 = xs.bsearch_index { |v, j| v >= vert[i][1] }.not_nil!
  y = ys.bsearch_index { |v, j| v >= vert[i][2] }.not_nil!
  x1.upto(x2 - 1) do |j|
    wall[y - 1][j] |= RIGHT
    wall[y][j] |= LEFT
    # puts "#{y - 1} #{j} RIGHT"
    # puts "#{y} #{j} LEFT"
  end
end
m.times do |i|
  y1 = ys.bsearch_index { |v, j| v >= horz[i][0] }.not_nil!
  y2 = ys.bsearch_index { |v, j| v >= horz[i][1] }.not_nil!
  x = xs.bsearch_index { |v, j| v >= horz[i][2] }.not_nil!
  y1.upto(y2 - 1) do |j|
    wall[j][x - 1] |= DOWN
    wall[j][x] |= UP
    # puts "#{j} #{x - 1} DOWN"
    # puts "#{j} #{x} UP"
  end
end
y0 = ys.bsearch_index { |v, i| v >= 0i64 }.not_nil!
x0 = xs.bsearch_index { |v, i| v >= 0i64 }.not_nil!
ans = 0i64
q = [{y0, x0}, {y0, x0 - 1}, {y0 - 1, x0}, {y0 - 1, x0 - 1}]
visited[y0][x0] = visited[y0][x0 - 1] = visited[y0 - 1][x0] = visited[y0 - 1][x0 - 1] = true
qi = 0
while qi < q.size
  cy, cx = q[qi]
  ans += (ys[cy + 1] - ys[cy]) * (xs[cx + 1] - xs[cx])
  if cy == 0 || cx == 0 || cy == ys.size - 1 || cx == xs.size - 1
    puts "INF"
    exit
  end
  if (wall[cy][cx] & UP) == 0 && !visited[cy][cx - 1]
    visited[cy][cx - 1] = true
    q << {cy, cx - 1}
  end
  if (wall[cy][cx] & DOWN) == 0 && !visited[cy][cx + 1]
    visited[cy][cx + 1] = true
    q << {cy, cx + 1}
  end
  if (wall[cy][cx] & LEFT) == 0 && !visited[cy - 1][cx]
    visited[cy - 1][cx] = true
    q << {cy - 1, cx}
  end
  if (wall[cy][cx] & RIGHT) == 0 && !visited[cy + 1][cx]
    visited[cy + 1][cx] = true
    q << {cy + 1, cx}
  end
  qi += 1
end
puts ans
