def inf
  puts "INF"
  exit
end

def explore(xx,yy)
  if xx==0 || xx==$x.size || yy==0 || yy==$y.size then inf end
  $mp[xx*2][yy*2] = 2
  #mps
  $ans += ($x[xx]-$x[xx-1])*($y[yy]-$y[yy-1])
  explore(xx+1,yy) if $mp[xx*2+1][yy*2] == 0 && $mp[xx*2+2][yy*2] == 0
  explore(xx-1,yy) if $mp[xx*2-1][yy*2] == 0 && $mp[xx*2-2][yy*2] == 0
  explore(xx,yy-1) if $mp[xx*2][yy*2-1] == 0 && $mp[xx*2][yy*2-2] == 0
  explore(xx,yy+1) if $mp[xx*2][yy*2+1] == 0 && $mp[xx*2][yy*2+2] == 0
end

n,m = gets.strip.split.map(&:to_i)
$x = []
$y = []
vxxy = []
n.times { |i|
  a,b,c = gets.strip.split.map(&:to_i)
  vxxy.append [a,b,c]
  $x.append a
  $x.append b
  $y.append c
}
hxyy = []
m.times {
  a,b,c = gets.strip.split.map(&:to_i)
  hxyy.append [a,b,c]
  $x.append a
  $y.append b
  $y.append c
}
$x.uniq!
$x.sort!
$y.uniq!
$y.sort!

$mp = Array.new($x.size * 2 + 1){Array.new($y.size * 2 + 1, 0)}
vxxy.each do |a,b,c|
  l = $x.index(a)
  m = $x.index(b)
  n = $y.index(c)
  (l*2+1).upto(m*2+1) {|i| $mp[i][n*2+1] = 1}
end 
hxyy.each do |a,b,c|
  l = $x.index(a)
  m = $y.index(b)
  n = $y.index(c)
  (m*2+1).upto(n*2+1) {|i| $mp[l*2+1][i] = 1}
end
$ans = 0
xx = $x.index{|v|v>=0}
yy = $y.index{|v|v>=0}
if !xx || !yy then inf end
explore(xx, yy)
p $ans