using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;

using E = System.Linq.Enumerable;

internal partial class Solver {
    public int[] Dx = new int[] { 0, 1, 0, -1 };
    public int[] Dy = new int[] { 1, 0, -1, 0 };
    public void Run() {
        var n = ni();
        var m = ni();
        var a = new int[n];
        var b = new int[n];
        var c = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = ni();
            b[i] = ni();
            c[i] = ni();
        }
        var d = new int[m];
        var e = new int[m];
        var f = new int[m];
        for (int i = 0; i < m; i++) {
            d[i] = ni();
            e[i] = ni();
            f[i] = ni();
        }
        var xs = c.Concat(e).Concat(f).Concat(new[] { 0 }).Distinct().OrderBy(x => x).ToArray();
        var ys = a.Concat(b).Concat(d).Concat(new[] { 0 }).Distinct().OrderBy(x => x).ToArray();

        var xsIndex = E.Range(0, xs.Length).ToDictionary(i => xs[i], i => i);
        var ysIndex = E.Range(0, ys.Length).ToDictionary(i => ys[i], i => i);

        var height = ys.Length * 2 - 1;
        var width = xs.Length * 2 - 1;
        var map = new bool[height * width];
        var xWidth = new int[width];
        var yWidth = new int[height];

        for (int i = 0; i + 1 < xs.Length; i++) {
            xWidth[2 * i + 1] = xs[i + 1] - xs[i];
        }
        for (int i = 0; i + 1 < ys.Length; i++) {
            yWidth[2 * i + 1] = ys[i + 1] - ys[i];
        }
        Func<int, int, int> ToId = (row, col) => row * width + col;
        for (int i = 0; i < n; i++) {
            var x = 2 * xsIndex[c[i]];
            var y1 = 2 * ysIndex[a[i]];
            var y2 = 2 * ysIndex[b[i]];
            for (int y = y1; y <= y2; y++) {
                map[ToId(y, x)] = true;
            }
        }
        for (int i = 0; i < m; i++) {
            var y = 2 * ysIndex[d[i]];
            var x1 = 2 * xsIndex[e[i]];
            var x2 = 2 * xsIndex[f[i]];
            for (int x = x1; x <= x2; x++) {
                map[ToId(y, x)] = true;
            }
        }
        long ans = 0;


        var sx = 2 * xsIndex[0];
        var sy = 2 * ysIndex[0];
        var queue = new Queue<int>();
        if (sx >= 1) queue.Enqueue(ToId(sy, sx - 1));
        if (sx + 1 < width) queue.Enqueue(ToId(sy, sx + 1));
        if (sy >= 1) queue.Enqueue(ToId(sy - 1, sx));
        if (sy + 1 < height) queue.Enqueue(ToId(sy + 1, sx));
        var visited = new bool[height * width];
        while (queue.Count > 0) {
            var p = queue.Dequeue();
            if (visited[p]) continue;
            var cx = p % width;
            var cy = p / width;
            visited[p] = true;
            ans += 1L * yWidth[cy] * xWidth[cx];

            for (int k = 0; k < 4; k++) {
                var nx = cx + Dx[k];
                var ny = cy + Dy[k];
                var np = ToId(ny, nx);
                if (!((0 <= nx && nx < width) && (0 <= ny && ny < height))) {
                    ans = long.MaxValue;
                    break;
                }
                if (map[np]) continue;
                if ((cx & 1) == 0 || (cy & 1) == 0) {
                    if (visited[np]) continue;
                    queue.Enqueue(np);
                    continue;
                }
                var nx2 = cx + Dx[k] * 2;
                var ny2 = cy + Dy[k] * 2;
                var np2 = ToId(ny2, nx2);
                if (!((0 <= nx2 && nx2 < width) && (0 <= ny2 && ny2 < height))) {
                    ans = long.MaxValue;
                    break;
                }
                if (visited[np2]) continue;
                queue.Enqueue(np2);
            }
            if (ans == long.MaxValue) break;
        }

        cout.WriteLine(ans == long.MaxValue ? "INF" : ans.ToString());
    }
}

// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
    public static void Main() {
#if LOCAL
        byte[] inputBuffer = new byte[1000000];
        var inputStream = Console.OpenStandardInput(inputBuffer.Length);
        using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {
            Console.SetIn(reader);
            new Solver(Console.In, Console.Out).Run();
        }
#else
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver(Console.In, Console.Out).Run();
        Console.Out.Flush();
#endif
    }

#pragma warning disable IDE0052
    private readonly TextReader cin;
    private readonly TextWriter cout;
#pragma warning restore IDE0052

    public Solver(TextReader reader, TextWriter writer)
        : base(reader) {
        cin = reader;
        cout = writer;
    }
    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer) {
    }

#pragma warning disable IDE1006
#pragma warning disable IDE0051
    private int ni() { return NextInt(); }
    private int[] ni(int n) { return NextIntArray(n); }
    private long nl() { return NextLong(); }
    private long[] nl(int n) { return NextLongArray(n); }
    private double nd() { return NextDouble(); }
    private double[] nd(int n) { return NextDoubleArray(n); }
    private string ns() { return Next(); }
    private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}

internal static class LinqPadExtension {
    [Conditional("DEBUG")]
    public static void Dump<T>(this T obj) {
#if DEBUG
        LINQPad.Extensions.Dump(obj);
#endif
    }
}

public class Scanner {
    private readonly TextReader Reader;
    private readonly CultureInfo ci = CultureInfo.InvariantCulture;

    private readonly char[] buffer = new char[2 * 1024];
    private int cursor = 0, length = 0;
    private string Token;
    private readonly StringBuilder sb = new StringBuilder(1024);

    public Scanner()
        : this(Console.In) {
    }

    public Scanner(TextReader reader) {
        Reader = reader;
    }

    public int NextInt() { return checked((int)NextLong()); }
    public long NextLong() {
        var s = Next();
        long r = 0;
        int i = 0;
        bool negative = false;
        if (s[i] == '-') {
            negative = true;
            i++;
        }
        for (; i < s.Length; i++) {
            r = r * 10 + (s[i] - '0');
#if DEBUG
            if (!char.IsDigit(s[i])) throw new FormatException();
#endif
        }
        return negative ? -r : r;
    }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size) {
        string[] array = new string[size];
        for (int i = 0; i < size; i++) {
            array[i] = Next();
        }

        return array;
    }
    public int[] NextIntArray(int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextInt();
        }

        return array;
    }

    public long[] NextLongArray(int size) {
        long[] array = new long[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextLong();
        }

        return array;
    }

    public double[] NextDoubleArray(int size) {
        double[] array = new double[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextDouble();
        }

        return array;
    }

    public string Next() {
        if (Token == null) {
            if (!StockToken()) {
                throw new Exception();
            }
        }
        var token = Token;
        Token = null;
        return token;
    }

    public bool HasNext() {
        if (Token != null) {
            return true;
        }

        return StockToken();
    }

    private bool StockToken() {
        while (true) {
            sb.Clear();
            while (true) {
                if (cursor >= length) {
                    cursor = 0;
                    if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
                        break;
                    }
                }
                var c = buffer[cursor++];
                if (33 <= c && c <= 126) {
                    sb.Append(c);
                } else {
                    if (sb.Length > 0) break;
                }
            }

            if (sb.Length > 0) {
                Token = sb.ToString();
                return true;
            }

            return false;
        }
    }
}


Measured memory_bytes: 82860