from collections import*
LI=lambda:[int(i)for i in input().split()]

F=1<<65
n,m=LI()
Z=[set(),set()]
X=set([0,F,-F])
Y=set(X)
V=[]
H=[]
for i in range(n):
    a,b,c=LI()
    V.append(((a,b),c))
    Y.add(c)
    X.add(a)
    X.add(b)
 
n+=2
V.append(((-F,F),F))
V.append(((-F,F),-F))
 
for i in range(m):
    a,b,c=LI()
    H.append(((b,c),a))
    X.add(a)
    Y.add(b)
    Y.add(c)
 
m+=2
H.append(((-F,F),F))
H.append(((-F,F),-F))


xdc=dict(enumerate(sorted(X)));nx=len(xdc)
ydc=dict(enumerate(sorted(Y)));ny=len(ydc)

xdcr={j:i for i,j in xdc.items()}
ydcr={j:i for i,j in ydc.items()}

mpy=[[0]*-~nx for i in range(ny+1)]
mpx=[i[:]for i in mpy]

for (a,b),c in V:
    mpx[ydcr[c]][xdcr[a]]+=1
    mpx[ydcr[c]][xdcr[b]]+=-1
for i in range(ny+1):
    for j in range(nx):
        mpx[i][j+1]+=mpx[i][j]
        
for (e,f),d in H:
    mpy[ydcr[e]][xdcr[d]]+=1
    mpy[ydcr[f]][xdcr[d]]+=-1
for j in range(nx+1):
    for i in range(ny):
        mpy[i+1][j]+=mpy[i][j]

v=[[0]*-~nx for i in range(ny+1)]
q=deque([(xdcr[0],ydcr[0])])
v[ydcr[0]][xdcr[0]]=1

a=0
while q:
    cx,cy=q.popleft()
    a+=(xdc[cx]-xdc[cx+1])*(ydc[cy]-ydc[cy+1])
    for dx,dy in [(-1,0),(1,0),(0,1),(0,-1)]:
        nbx=cx+dx
        nby=cy+dy
        if (not 0<=nbx<nx) or (not 0<=nby<ny) or v[nby][nbx]==1:
            continue
        if dy!=0:
            if mpx[cy-~dy//2][cx]==0:
                q.append((nbx,nby))
                v[nby][nbx]=1
        else:
            if mpy[cy][cx-~dx//2]==0:
                q.append((nbx,nby))
                v[nby][nbx]=1
if a>=F:a='F'
print(a)
