def inf
  puts "INF"
  exit
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.append 0
y.append 0
x.uniq!
x.sort!
y.uniq!
y.sort!

mpw = y.size * 2 + 1
mp = Array.new((x.size * 2 + 1)*mpw)
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*mpw+n*2+1] = true}
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)*mpw+i] = true}
end
ans = 0
q = [[x.index(0),y.index(0)]]
while !q.empty?
  xx,yy = q.shift
  inf if xx==0 || xx==x.size || yy==0 || yy==y.size
  x2 = xx * 2
  y2 = yy * 2
  mpi = x2*mpw+y2
  next if mp[mpi]
  mp[mpi] = true
  ans += (x[xx]-x[xx-1])*(y[yy]-y[yy-1])
  q.append [xx+1,yy] if !mp[mpi+mpw] && !mp[mpi+mpw+mpw]
  q.append [xx-1,yy] if !mp[mpi-mpw] && !mp[mpi-mpw-mpw]
  q.append [xx,yy+1] if !mp[mpi+1] && !mp[mpi+2]
  q.append [xx,yy-1] if !mp[mpi-1] && !mp[mpi-2]
end
p ans