Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,m = map(int, input().split())
mpX = {}
mpY = {}
rmpX = {}
rmpY = {}

lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0, 10**10])
ix = 0
iy = 0
for i in range(n):
    t = tuple(map(int, input().split()))
    lx[i] = t
    sx.add(t[0])
    sx.add(t[1])
    sy.add(t[2])
        
for i in range(m):
    t = tuple(map(int, input().split()))
    ly[i] = t
    sx.add(t[0])
    sy.add(t[1])
    sy.add(t[2])
        
xs = list(sx)
ys = list(sy)
xs.sort(); ys.sort()

wx = len(xs)*2
wy = len(ys)*2
bs = [[1]*wy for _ in range(wx)]
for i, (x0, x1, y) in enumerate(lx):
    ix0 = xs.index(x0)*2
    ix1 = xs.index(x1)*2
    iy = ys.index(y)*2
    for ii in range(ix0, ix1):
        bs[ii][iy] = -1
for i, (x, y0, y1) in enumerate(ly):
    ix = xs.index(x)*2
    iy0 = ys.index(y0)*2
    iy1 = ys.index(y1)*2
    for ii in range(iy0, iy1):
        bs[ix][ii] = -1

xx = xs.index(0)*2
yy = ys.index(0)*2
s = [(xx,yy)]
dx = [-1,0,1,0]
dy = [0,-1,0,1]
ans = 0
end = False
while s:
    ix,iy = s.pop()
    for x, y in zip(dx,dy):
        ixx = ix + x
        iyy = iy + y
        if bs[ixx][iyy]!=1:
            continue
        if ixx==0 or ixx==wx-1 or iyy==0 or iyy==wy-1:
            print("INF")
            s = []
            end = True
            break
        s.append((ixx, iyy))
        bs[ixx][iyy] = 2
        if (ixx)%2 and (iyy)%2:
            ans += (xs[ixx//2+1] - xs[ixx//2]) * (ys[iyy//2+1] - ys[iyy//2])
if not end:
    print(ans)


Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())

lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0, 10**10])
ix = 0
iy = 0
for i in range(n):
    t = tuple(map(int, input().split()))
    lx[i] = t
    sx.add(t[0])
    sx.add(t[1])
    sy.add(t[2])
        
for i in range(m):
    t = tuple(map(int, input().split()))
    ly[i] = t
    sx.add(t[0])
    sy.add(t[1])
    sy.add(t[2])
        
xs = list(sx)
ys = list(sy)
xs.sort(); ys.sort()

wx = len(xs)*2
wy = len(ys)*2
bs = [[1]*wy for _ in range(wx)]
for i, (x0, x1, y) in enumerate(lx):
    ix0 = xs.index(x0)*2
    ix1 = xs.index(x1)*2
    iy = ys.index(y)*2
    for ii in range(ix0, ix1):
        bs[ii][iy] = -1
for i, (x, y0, y1) in enumerate(ly):
    ix = xs.index(x)*2
    iy0 = ys.index(y0)*2
    iy1 = ys.index(y1)*2
    for ii in range(iy0, iy1):
        bs[ix][ii] = -1

xx = xs.index(0)*2+1
yy = ys.index(0)*2+1
s = [(xx,yy)]
dx = [-1,0,1,0]
dy = [0,-1,0,1]
ans = 0
end = False
while s:
    ix,iy = s.pop()
    for x, y in zip(dx,dy):
        ixx = ix + x
        iyy = iy + y
        if bs[ixx][iyy]!=1:
            continue
        ixx += x
        iyy += y
        if bs[ixx][iyy]!=1:
            continue
        if ixx<0 or ixx>=wx-1 or iyy<0 or iyy>=wy-1:
            print("INF")
            s = []
            end = True
            break
        bs[ixx][iyy] = 2
        ans += (xs[ixx//2+1] - xs[ixx//2]) * (ys[iyy//2+1] - ys[iyy//2])
        s.append((ixx, iyy))
            
if not end:
    print(ans)