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;
using System.Runtime.CompilerServices;

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 char[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];
        }
        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[y, x] = '#';
            }
        }
        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[y, x] = '#';
            }
        }
        long ans = 0;

        var sx = 2 * xsIndex[0];
        var sy = 2 * ysIndex[0];
        var queue = new Queue<int>();
        queue.Enqueue(sx);
        queue.Enqueue(sy);
        var visited = new bool[height, width];
        while (queue.Count > 0) {
            var cx = queue.Dequeue();
            var cy = queue.Dequeue();
            if (visited[cy, cx]) continue;
            visited[cy, cx] = true;
            ans += 1L * yWidth[cy] * xWidth[cx];
            for (int k = 0; k < 4; k++) {
                var nx = cx + Dx[k];
                var ny = cy + Dy[k];
                if (!((0 <= nx && nx < width) && (0 <= ny && ny < height))) {
                    ans = long.MaxValue;
                    break;
                }
                if (map[ny, nx] == '#' || visited[ny, nx]) continue;
                queue.Enqueue(nx);
                queue.Enqueue(ny);
            }
            if (ans == long.MaxValue) break;
        }

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

// A simple Queue of generic objects.  Internally it is implemented as a
// circular buffer, so Enqueue can be O(n).  Dequeue is O(1).
[Serializable]
public class FQueue<T> {
    private T[] _array;
    private int _head;       // The index from which to dequeue if the queue isn't empty.
    private int _tail;       // The index at which to enqueue if the queue isn't full.
    private int _size;       // Number of elements.
    private int _version;

    private const int MinimumGrow = 4;
    private const int GrowFactor = 200;  // double each time

    // Creates a queue with room for capacity objects. The default initial
    // capacity and grow factor are used.
    public FQueue() {
        _array = Array.Empty<T>();
    }

    // Creates a queue with room for capacity objects. The default grow factor
    // is used.
    public FQueue(int capacity) {
        _array = new T[capacity];
    }


    public int Count {
        get { return _size; }
    }

    // Removes all Objects from the queue.
    public void Clear() {
        if (_size != 0) {
            if (RuntimeHelpers.IsReferenceOrContainsReferences<T>()) {
                if (_head < _tail) {
                    Array.Clear(_array, _head, _size);
                } else {
                    Array.Clear(_array, _head, _array.Length - _head);
                    Array.Clear(_array, 0, _tail);
                }
            }

            _size = 0;
        }

        _head = 0;
        _tail = 0;
        _version++;
    }


    // Adds item to the tail of the queue.
    public void Enqueue(T item) {
        if (_size == _array.Length) {
            int newcapacity = (int)((long)_array.Length * (long)GrowFactor / 100);
            if (newcapacity < _array.Length + MinimumGrow) {
                newcapacity = _array.Length + MinimumGrow;
            }
            SetCapacity(newcapacity);
        }

        _array[_tail] = item;
        MoveNext(ref _tail);
        _size++;
        _version++;
    }

    // Removes the object at the head of the queue and returns it. If the queue
    // is empty, this method throws an
    // InvalidOperationException.
    public T Dequeue() {
        int head = _head;
        T[] array = _array;

        if (_size == 0) {
            ThrowForEmptyQueue();
        }

        T removed = array[head];
        if (RuntimeHelpers.IsReferenceOrContainsReferences<T>()) {
            array[head] = default!;
        }
        MoveNext(ref _head);
        _size--;
        _version++;
        return removed;
    }


    // Returns the object at the head of the queue. The object remains in the
    // queue. If the queue is empty, this method throws an
    // InvalidOperationException.
    public T Peek() {
        if (_size == 0) {
            ThrowForEmptyQueue();
        }

        return _array[_head];
    }


    // Returns true if the queue contains at least one object equal to item.
    // Equality is determined using EqualityComparer<T>.Default.Equals().
    public bool Contains(T item) {
        if (_size == 0) {
            return false;
        }

        if (_head < _tail) {
            return Array.IndexOf(_array, item, _head, _size) >= 0;
        }

        // We've wrapped around. Check both partitions, the least recently enqueued first.
        return
            Array.IndexOf(_array, item, _head, _array.Length - _head) >= 0 ||
            Array.IndexOf(_array, item, 0, _tail) >= 0;
    }

    // Iterates over the objects in the queue, returning an array of the
    // objects in the Queue, or an empty array if the queue is empty.
    // The order of elements in the array is first in to last in, the same
    // order produced by successive calls to Dequeue.
    public T[] ToArray() {
        if (_size == 0) {
            return Array.Empty<T>();
        }

        T[] arr = new T[_size];

        if (_head < _tail) {
            Array.Copy(_array, _head, arr, 0, _size);
        } else {
            Array.Copy(_array, _head, arr, 0, _array.Length - _head);
            Array.Copy(_array, 0, arr, _array.Length - _head, _tail);
        }

        return arr;
    }

    // PRIVATE Grows or shrinks the buffer to hold capacity objects. Capacity
    // must be >= _size.
    private void SetCapacity(int capacity) {
        T[] newarray = new T[capacity];
        if (_size > 0) {
            if (_head < _tail) {
                Array.Copy(_array, _head, newarray, 0, _size);
            } else {
                Array.Copy(_array, _head, newarray, 0, _array.Length - _head);
                Array.Copy(_array, 0, newarray, _array.Length - _head, _tail);
            }
        }

        _array = newarray;
        _head = 0;
        _tail = (_size == capacity) ? 0 : _size;
        _version++;
    }

    // Increments the index wrapping it if necessary.
    private void MoveNext(ref int index) {
        // It is tempting to use the remainder operator here but it is actually much slower
        // than a simple comparison and a rarely taken branch.
        // JIT produces better code than with ternary operator ?:
        int tmp = index + 1;
        if (tmp == _array.Length) {
            tmp = 0;
        }
        index = tmp;
    }

    private void ThrowForEmptyQueue() {
        Debug.Assert(_size == 0);
        throw new InvalidOperationException();
    }

    public void TrimExcess() {
        int threshold = (int)(((double)_array.Length) * 0.9);
        if (_size < threshold) {
            SetCapacity(_size);
        }
    }
}
// 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: 120896