n, m = read_line.split.map(&.to_i64)
ver_events = Hash(Int64, Array(Tuple(Int64, Symbol))).new do |h, k|
  h[k] = [] of Tuple(Int64, Symbol)
end
hor_events = Hash(Int64, Array(Tuple(Int64, Symbol))).new do |h, k|
  h[k] = [] of Tuple(Int64, Symbol)
end
n.times do
  a, b, c = read_line.split.map(&.to_i64)
  ver_events[c] << {a, :open}
  ver_events[c] << {b, :close}
end
m.times do
  d, e, f = read_line.split.map(&.to_i64)
  hor_events[d] << {e, :open}
  hor_events[d] << {f, :close}
end

vers = [] of Tuple(Int64, Int64, Int64)
ver_events.each do |c, events|
  events.sort_by! {|(y, type)| {y, type == :open ? -1_i64 : 1_i64}}
  depth = 0_i64
  open = 0_i64
  events.each do |(y, type)|
    if type == :open
      if depth == 0
        open = y
      end
      depth += 1
    else
      depth -= 1
      if depth == 0
        vers << {open, y, c}
      end
    end
  end
end
vers.sort_by! {|(a, b, c)| c}

hors = [] of Tuple(Int64, Int64, Int64)
hor_events.each do |f, events|
  events.sort_by! {|(x, type)| {x, type == :open ? -1_i64 : 1_i64}}
  depth = 0_i64
  open = 0_i64
  events.each do |(x, type)|
    if type == :open
      if depth == 0
        open = x
      end
      depth += 1
    else
      depth -= 1
      if depth == 0
        hors << {open, x, f}
      end
    end
  end
end
hors.sort_by! {|(d, e, f)| f}

start_ver = vers.find {|(a, b, c)| c > 0 && a <= 0 && 0 <= b}
if start_ver.nil?
  puts "INF"
  exit
end
class Dfs
  def initialize(@vers : Array(Tuple(Int64, Int64, Int64)), @hors : Array(Tuple(Int64, Int64, Int64)), start_ver, y)
    @points = Array(Tuple(Int64, Int64)).new
    dfs_ver(start_ver, y, true)
  end

  # dir => true: up, false: down
  def dfs_ver(ver, y, dir)
    a, b, c = ver
    if dir
      @hors.reverse_each do |(d, e, f)|
        ok = a <= f && f <= y && d < c && c <= e
        if ok
          @points << {c, f}
          dfs_hor({d, e, f}, c, true)
        end
      end
      dfs_ver(ver, a, false)
    else
      @hors.each do |(d, e, f)|
        ok = y <= f && f <= b && d <= c && c < e
        if ok
          @points << {c, f}
          dfs_hor({d, e, f}, c, false)
        end
      end
      dfs_ver(ver, b, true)
    end
  end

  # dir => true: left, false: right
  def dfs_hor(hor, x, dir)
    d, e, f = hor
    if dir
      @vers.reverse_each do |(a, b, c)|
        ok = d <= c && c <= x && a <= f && f < b
        if ok
          @points << {c, f}
          dfs_ver({a, b, c}, f, false)
        end
      end
      dfs_hor(hor, d, false)
    else
      @hors.each do |(a, b, c)|
        ok = x <= c && c <= e && a < f && f <= b
        if ok
          @points << {c, f}
          dfs_ver({a, b, c}, f, true)
        end
      end
      dfs_hor(hor, e, true)
    end
  end
end
Dfs.new(vers, hors, start_ver, 0_i64)
