using System;
using System.Numerics;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<int, int> mpX = new Dictionary<int,int>();
            Dictionary<int, int> mpY = new Dictionary<int, int>();
            Dictionary<int, int> tmp = new Dictionary<int, int>();
            List<L> lh = new List<L>();
            List<L> lv = new List<L>();
            ReadOnlyCollection<int> dx = Array.AsReadOnly(new int[]{ -1, 0, 1, 0});
            ReadOnlyCollection<int> dy = Array.AsReadOnly(new int[] {0, -1, 0, 1});
            int[] nm = Array.ConvertAll(System.Console.ReadLine().Split(' '), int.Parse);
            mpX.Add(0, 0);
            mpY.Add(0, 0);
            for (int i=0; i<nm[0];i++)
            {
                int[] abc = Array.ConvertAll(System.Console.ReadLine().Split(' '), int.Parse);

               lh.Add(new L(abc[0], abc[1], abc[2]));
               if(mpX.ContainsKey(abc[0])){mpX[abc[0]] = 0;}else{ mpX.Add(abc[0], 0);}
               if (mpX.ContainsKey(abc[1])) { mpX[abc[1]] = 0; } else { mpX.Add(abc[1], 0); }
               if (mpY.ContainsKey(abc[2])) { mpY[abc[2]] = 0; } else { mpY.Add(abc[2], 0); }
            }
            for (int i = 0; i < nm[1]; i++)
            {
                int[] abc = Array.ConvertAll(System.Console.ReadLine().Split(' '), int.Parse);

                if (mpY.ContainsKey(abc[1])) { mpY[abc[1]] = 0; } else { mpY.Add(abc[1], 0); }
                if (mpY.ContainsKey(abc[2])) { mpY[abc[2]] = 0; } else { mpY.Add(abc[2], 0); }
                if (mpX.ContainsKey(abc[0])) { mpX[abc[0]] = 0; } else { mpX.Add(abc[0], 0); }
                lv.Add(new L(abc[1], abc[2], abc[0]));
            }
            List<int> xs = new List<int>();
            List<int> ys = new List<int>();
            mpX = new Dictionary<int,int>( mpX.OrderBy((x) => x.Key));
            foreach( KeyValuePair<int,int> i in mpX)
            {
                tmp.Add(i.Key,xs.Count);
                xs.Add(i.Key);
            }
            mpX = new Dictionary<int, int>(tmp);
            tmp.Clear();

            mpY = new Dictionary<int, int>(mpY.OrderBy((x) => x.Key));
            foreach (KeyValuePair<int, int> i in mpY)
            {
                tmp.Add(i.Key, ys.Count);
                ys.Add(i.Key);
            }
            mpY = new Dictionary<int, int>(tmp);
            tmp.Clear();

            int h = xs.Count * 2;
            int w = ys.Count * 2;
            int[,]  d = new int[h, w];
            for(int i=0;i< nm[0];i++)
            {
                int a = mpX[lh[i].a] * 2;
                int b = mpX[lh[i].b] * 2;
                int c = mpY[lh[i].c] * 2;
                for(int x =a; x<=b; ++x)
                {
                    d[x,c] = -1;
                }
            }
            for (int i = 0; i < nm[1]; i++)
            {
                int a = mpY[lv[i].a] * 2;
                int b = mpY[lv[i].b] * 2;
                int c = mpX[lv[i].c] * 2;
                for (int y = a; y <= b; ++y )
                {
                    d[c,y] = -1;
                }
            }
            var que = new Queue<KeyValuePair<int,int>>();
            int sx = mpX[0] * 2, sy = mpY[0] * 2;
            d[sx, sy] = 1;
            que.Enqueue(new KeyValuePair<int,int>(sx, sy));
            while(que.Count !=0)
            {
                (int x,int y) = que.Dequeue() ;
                for(int v = 0; v < 4; v++)
                {
                    int nx = x + dx[v], ny = y + dy[v];
                    if (nx < 0 || nx >= h) continue;
                    if (ny < 0 || ny >= w) continue;
                    if (d[nx,ny] != 0) continue;
                    d[nx,ny] = 1;
                    que.Enqueue(new KeyValuePair<int,int>(nx, ny));
                }
            }
            // BigInteger ans = 0;
            long ans = 0;
                for (int x=0; x<h;x++)
            {
                for(int y=0; y<w;y++)
                {
                    if (d[x, y] != 1) continue;
                    if(x==0 || x== h-1 || y==0 || y == w - 1)
                    {
                        System.Console.WriteLine("INF");
                        return;
                    }
                    if (x % 2 == 0 || y % 2 == 0) continue;
                    long ex = xs[x / 2 + 1] - xs[x / 2];
                    long ey = ys[y / 2 + 1] - ys[y / 2];
                    ans += ex * ey;
                }
                System.Console.WriteLine(ans);
            }
      
        }
        public struct L
        {
            public int a, b, c;
            public L(int a=0,int b=0,int c=0)
            {
                this.a = a;
                this.b = b;
                this.c = c;
            }
        }
    }
}
