import os
import sys
from io import BytesIO, IOBase

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

xs = set([0])
ys = set([0])

vert = []
for _ in range(n):
    a, b, c = map(int, input().split())
    xs.add(a)
    xs.add(b)
    ys.add(c)
    vert.append((a,b,c))

hor = []
for _ in range(m):
    d, e, f = map(int, input().split())
    xs.add(d)
    ys.add(e)
    ys.add(f)
    hor.append((d,e,f))

xs = list(xs)
ys = list(ys)
xs.sort()
ys.sort()

revX = dict()
revY = dict()
for i in range(len(xs)):
    revX[xs[i]] = i
for i in range(len(ys)):
    revY[ys[i]] = i

width = len(xs) + 1
height = len(ys) + 1

visited = [[False] * height for _ in range(width)]

adj = [[15]*height for _ in range(width)]
for a, b, c in vert:
    ra, rb, rc = revX[a], revX[b], revY[c]
    for i in range(ra + 1, rb + 1):
        adj[i][rc] &= 13
        adj[i][rc + 1] &= 14

for d, e, f in hor:
    rd, re, rf = revX[d], revY[e], revY[f]
    for j in range(re + 1, rf + 1):
        adj[rd][j] &= 7
        adj[rd + 1][j] &= 11

dX = [0,0,-1,1]
dY = [-1,1,0,0]

stack = []
start = (revX[0], revY[0])
stack.append(start)
visited[start[0]][start[1]] = True

inf = False
while stack:
    nexX, nexY = stack.pop()
    poss = adj[nexX][nexY]
    for d in range(4):
        if poss & (1 << d):
            newX = nexX + dX[d]
            newY = nexY + dY[d]
            if not visited[newX][newY]:
                visited[newX][newY] = True
                stack.append((newX, newY))
                if newX == 0 or newX == width - 1 or newY == 0 or newY == height - 1:
                    inf = True
                if inf:
                    stack = []

if inf:
    print('INF')
else:
    area = 0
    for i in range(width-1):
        xRange = (xs[i] - xs[i - 1])
        for j in range(height-1):
            if visited[i][j]:
                area += xRange * (ys[j] - ys[j-1])
    print(area)
            
        
