a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = False
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = True
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (k % i == 0) & (n % i == 0):
            g = i
    ai = n // g
    for i in range(1, max):
        if (k % i == 0) & (m % i == 0):
            g = i
    bi = m // g
    if k:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a = b
        b = a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    g = gcd(m, k)
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('0 {}'.format(bi))
    print('{} 0'.format(ai))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (k % i == 0) & (n % i == 0):
            g = i
    ai = n // g
    for i in range(1, max):
        if (k % i == 0) & (m % i == 0):
            g = i
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if bul:
    print('YES')
    print('0 0')
    d = gcd(n, k)
    ki = k // d
    ai = n // d
    bi =  2*m // ki
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    g = gcd(m, k)
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = False
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = True
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (m % i == 0) & (n % i == 0):
            g = i
    ki = k // g
    ai = n // g
    bi = ki // g
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    ki = k // d
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    bi =  2*m // ki
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = False
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = True
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (m % i == 0) & (n % i == 0):
            g = i
    ki = k // g
    ai = n // g
    bi = ki // g
    if k:
        ai = ai * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if bul:
    print('YES')
    print('0 0')
    d = gcd(n, k)
    ki = k // d
    ni = n // d
    if ki != 1:
        ai = 2*ni
        bi = 2*m//ki
    else:
        ai = n // d
        bi =  2*m // ki
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    g = gcd(m, k)
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(bi))
    print('0 {}'.format(ai))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    d = gcd(n, k)
    ki = k // d
    ai = n // d
    bi =  2*m // ki
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if bul:
    print('YES')
    print('0 0')
    d = gcd(n, k)
    ki = k // d
    ni = n // d
    if ki != 1:
        ai = ni
        bi = 2*m//ki
    if ki == 1:
        ai = 2*ni
        bi =  m
    print('0 {}'.format(bi))
    print('{} 0'.format(ai))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = False
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = True
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (k % i == 0) & (n % i == 0):
            g = i
    ki = k // g
    ai = n // g
    bi = ki // g
    if k:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = False
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = True
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (m % i == 0) & (n % i == 0):
            g = i
    ki = k // g
    ai = n // g
    bi = ki // g
    if k:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n / g
    g = gcd(m, k)
    bi = m / g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if bul:
    print('YES')
    print('0 0')
    d = gcd(n, k)
    ki = k // d
    ni = n // d
    if ki != 1:
        ai = 2*ni
        bi = 2*m//ki
    else:
        ai = 2*ni
        bi =  m
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a = b
        b = a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    g = gcd(m, k)
    bi = m // g
    print('0 {}'.format(bi))
    print('{} 0'.format(ai))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if bul:
    print('YES')
    print('0 0')
    d = gcd(n, k)
    ki = k // d
    ni = n // d
    if ki != 1:
        ai = 2*ni
        bi = 2*m//ki
    if ki == 1:
        ai = 2*ni
        bi =  m
    print('0 {}'.format(bi))
    print('{} 0'.format(ai))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = False
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = True
if bul:
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max):
        if (m % i == 0) & (n % i == 0):
            g = i
    ki = k // g
    ai = n // g
    bi = ki // g
    if k:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    if n > m:
        max = n
    else:
        max = m
    for i in range(1, max**(1/2)):
        if (k % i == 0) & (n % i == 0):
            g = i
    ai = n // g
    for i in range(1, max):
        if (k % i == 0) & (m % i == 0):
            g = i
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    g = gcd(m, k)
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('0 {}'.format(bi))
    print('{} 0'.format(ai))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

a = input().split(' ')
b = list(a)
n = int(b[0])
m = int(b[1])
k = int(b[2])
bu = True
bul = True
if (2*n*m % k != 0):
    print('NO')
    bul = False
if k % 2 == 0:
    k = k // 2
    bu = False
if bul:
    print('YES')
    print('0 0')
    g = gcd(n, k)
    ai = n // g
    g = gcd(m, k)
    bi = m // g
    if bu:
        if ai < n:
            ai = ai * 2
        else:
            bi = bi * 2
    print('{} 0'.format(ai))
    print('0 {}'.format(bi))


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
x = gcd(m,k)
y = gcd(n,k)
if x > y:
    s = (m//x)*n
else:
    s = m*(n//y)
if (2*s)%(k//max(x,y)) == 0:
    print('YES')
    s = s//(k//max(x,y))*2
    if x > y:
        print(0,0)
        if x < k:
            print(2*n//(k//x),0)
            print(0,(m//x))
        else:
            print(n//(k//x),0)
            print(0,(2*m//x))
    else:
        print(0,0)
        if y < k:
            print((n//y),0)
            print(0,2*m//(k//y))
        else:
            print(2*n//y,0)
            print(0,m//(k//y))
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
if (n*m)%k == 0:
    s = n*m//k
    x = gcd(m,k)
    print(0,0)
    print(n//(k//x),0)
    print(0,2*m//x)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
x = gcd(m,k)
y = gcd(n,k)
if x > y:
    s = (m//x)*n
else:
    s = m*(n//y)
if s%(k//max(x,y)) == 0:
    print('YES')
    s = s//(k//max(x,y))
    if x > 1:
        print(0,0)
        print(n//(k//x),0)
        print(0,m//x*2)
    else:
        print(0,0)
        print(n//(k//x)*2,0)
        print(0,m//x)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
x = gcd(m,k)
y = gcd(n,k)
if x > y:
    s = (m//x)*n
else:
    s = m*(n//y)
if s%(k//min(x,y)) == 0:
    print('YES')
    s = s//(k//min(x,y))
    if x > 1:
        print(0,0)
        print(n//(k//x),0)
        print(0,m//x*2)
    else:
        print(0,0)
        print(n//(k//x)*2,0)
        print(0,m//x)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
x = gcd(m,k)
y = gcd(n,k)
if x > y:
    s = (m//x)*n
else:
    s = m*(n//y)
if (2*s)%(k//max(x,y)) == 0:
    print('YES')
    s = s//(k//max(x,y))*2
    if x > 1:
        print(0,0)
        print(n//(k//x),0)
        print(0,m//x*2)
    else:
        print(0,0)
        print(n//(k//x)*2,0)
        print(0,m//x)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
s = n*m
if s%k == 0:
    print('YES')
    s = n*m//k
    print(0,0)
    print(1,1)
    print(1,2*s+1)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
if (n*m)%k == 0:
    s = n*m//k
    x = gcd(m,k)
    print('YES')
    print(0,0)
    print(n//(k//x),0)
    print(0,2*m//x)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
if (n*m)%k == 0:
    print('YES')
    s = n*m//k
    x = gcd(m,k)
    if x > 1:
        print(0,0)
        print(n//(k//x),0)
        print(0,2*m//x)
    else:
        print(0,0)
        print(2*n//(k//x),0)
        print(0,m//x)
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
x = gcd(m,k)
y = gcd(n,k)
if x > y:
    s = (m//x)*n
else:
    s = m*(n//y)
if (2*s)%(k//max(x,y)) == 0:
    print('YES')
    s = s//(k//max(x,y))*2
    if x > y:
        print(0,0)
        if x < k:
            print(n//(k//x)*2,0)
            print(0,(m//x))
        else:
            print(n//(k//x),0)
            print(0,(m//x)*2)
    else:
        print(0,0)
        if y < k:
            print((n//y),0)
            print(0,m//(k//y)*2)
        else:
            print(2*(n//y),0)
            print(0,m//(k//y))
else:
    print('NO')


#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
    x = max(a,b)
    y = min(a,b)
    r = x%y
    while r > 0:
        x = y
        y = r
        r = x%y
    return y
if (n*m)%k == 0:
    s = n*m//k
    print('YES')
    x = gcd(m,k)
    print(0,0)
    print(n//(k//x),0)
    print(0,m//x)
else:
    print('NO')


import sys
import bisect
try:
	fin = open('in')
except:
	fin = sys.stdin
input = fin.readline

from math import gcd
n, m, k = map(int, input().split())
area = n * m / k
f=True
if (2*n*m)%k==0:
	if k%2==0:
		f=False
		k//=2
	print("YES")
	a=n//gcd(n,k)
	k//=gcd(n,k)
	b=m//gcd(m,k)
	k//=gcd(m,k)
	#should be 1?
	if f:
		if a<n:a*=2
		else:b*=2
	print(0,0)
	print(a,0)
	print(0,b)
else:
	print("NO")


n, m, k = map(int, input().split())
if ((2 * n * m) % k != 0):
    print("NO")
else:
    s = (n * m) / k
    s = int(s * 2)
    print("YES")
    print(0, 0)
    print(n, 1)
    print(n - s % (n + 1), s // (n + 1) + 1)


n, m, k = map(int, input().split())
if ((2 * n * m) % k != 0):
    print("NO")
else:
    s = (n * m) / k
    s = int(s * 2 + 1)
    print("YES")
    print(0, 0)
    print(n, 1)
    print(n - s % (n + 1), s // (n + 1) + 1)


n, m, k = map(int, input().split())
if (((n * m) / k) * 2 != int(((n * m) / k) * 2)):
    print("NO")
else:
    s = (n * m) / k
    s = int(s * 2)
    print("YES")
    print(0, 0)
    print(n, 1)
    print(n - s % (n + 1), s // (n + 1) + 1)


n, m, k = map(int, input().split())
if ((2 * n * m) % k != 0):
    print("NO")
else:
    if (k == 2):
        print("YES")
        print(0, 0)
        print(n, 0)
        print(0, m)
    else:
        s = (n * m) / k
        s = int(s * 2)
        print("YES")
        print(0, 0)
        print(n, 1)
        print(((n - 1) - (s - 1) % n), (s - 1) // n + 1)


n, m, k = map(int, input().split())
if (n * m * 2) % k != 0:
    print("NO")
    exit()
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
div = 0
if k % 2 == 0:
    k //= 2
    div = 1
g = gcd(n, k)
a = n // g
b = (m * g) // k
if div == 1:
    if 2 * a <= n:
        a *= 2
    else:
        b *= 2
print("YES")
print(b, 0)
print(a, 0)
print(0, 0)


n, m, k = map(int, input().split())
if (n * m * 2) % k != 0:
    print("NO")
    exit()
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
div = 0
if k % 2 == 0:
    k //= 2
    div = 1
g = gcd(n, k)
a = n // g
b = (m * g) // k
if div == 1:
    if 2 * a <= n:
        a *= 2
    else:
        b *= 2
print("YES")
print(a, 0)
print(0, b)
print(0, 0)


n, m, k = map(int, input().split())
if (n * m * 2) % k != 0:
    print("NO")
    exit()
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
div = 0
if k % 2 == 0:
    k //= 2
    div = 1
g = gcd(n, k)
a = n // g
b = (m * g) // k
if not div:
    if 2 * a <= n:
        a *= 2
    else:
        b *= 2
print("YES")
print(a, 0)
print(0, b)
print(0, 0)


from sys import stdin
input=lambda : stdin.readline().strip()
lin=lambda :list(map(int,input().split()))
iin=lambda :int(input())
main=lambda :map(int,input().split())
from math import ceil,sqrt,factorial,log
from collections import deque
from bisect import bisect_left
def gcd(a,b):
	a,b=max(a,b),min(a,b)
	while a%b!=0:
		a,b=b,a%b
	return b
def solve():
	n,m,k=main()
	if (2*m*n)%k!=0:
		print("NO")
	else:
		t=(2*n*m)//k
		print("YES")
		print(0,0)
		x=0
		y=0
		f=0
		if k%2==0:
			k=k//2
			f=1
		x=gcd(n,k)
		k=k//x
		a=n//x
		x=gcd(m,k)
		k=k//x
		b=m//x
		if f==0:
			if a<n:
				a+=a
			else:
				b+=b
		print(a,0)
		print(0,b)

qwe=1
# qwe=int(input())
for _ in range(qwe):
	solve()


n, m, k = map(int, input().split())
if 2*n*m % k:
    print('NO')
else:
    print('YES')
    print(0, 0)
    print(n, 1)
    y = (2 * m + k - 1) // k
    x = 2 * y * n - n - m * y + m - 2 * n * m // k
    print(x, y)


n, m, k = map(int, input().split())
if 2*n*m % k:
    print('NO')
else:
    print('YES')
    print(0, 0)
    print(n, 1)
    print(n * ((2 * m + k - 1) // k) - 2 * n * m // k, (2 * m + k - 1) // k)


def GCD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b

s = input().split(' ')
n = int(s[0])
m = int(s[1])
k = int(s[2])

if 2 * n * m % k != 0:
	print("NO")
	exit()

k1 = GCD(n,k);
k2 = k // k1;
x = n // k1;
y = m // k2;
if 2 * x <= n:
	x *= 2
else:
	y *= 2

print("YES")
print(0, y)
print(0, 0)
print(x, 0)


def GCD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b

s = input().split(' ')
n = int(s[0])
m = int(s[1])
k = int(s[2])

divided = False

if k % 2 == 0:
	k = k // 2
	divided = True

if 2 * n * m % k != 0:
	print("NO")
	exit()

k1 = GCD(n,k);
k2 = k // k1;
x = n // k1;
y = m // k2;
if not divided:
	if 2 * x <= n:
		x *= 2
	elif 2 * y <= m:
		y *= 2
	else:
		print("NO")
		exit()

print("YES")
print(0, y)
print(0, 0)
print(x, 0)


def GCD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b

s = input().split(' ')
n = int(s[0])
m = int(s[1])
k = int(s[2])

divided = False

if 2 * n * m % k != 0:
	print("NO")
	exit()

if k % 2 == 0:
	k = k // 2
	divided = True

k1 = GCD(n,k);
k2 = k // k1;
x = n // k1;
y = m // k2;
if not divided:
	if 2 * x <= n:
		x *= 2
	elif 2 * y <= m:
		y *= 2
	else:
		print("NO")
		exit()

print("YES")
print(0, y)
print(0, 0)
print(x, 0)


def GCD(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b

s = input().split(' ')
n = int(s[0])
m = int(s[1])
k = int(s[2])

if 2 * n * m % k != 0:
	print("NO")
	exit()

k1 = GCD(n,k);
k2 = k // k1;
x = n // k1;
y = m // k2;

if 2 * x <= n:
	x *= 2
elif 2 * y <= m:
	y *= 2
else:
	print("NO")
	exit()

print("YES")
print(0, y)
print(0, 0)
print(x, 0)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    print(0,0)
    print(a,0)
    print(0,b*2)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    print('YES')
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    print(0,0)
    print(a,0)
    print(0,b*2)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    print(0,0)
    print(a,0)
    print(0,b)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    print('YES')
    if k%2==0:
        k//=2
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks

    print(0,0)
    print(a,0)
    print(0,b)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    print('YES')
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    if a>b:
        b*=2
    else:
        a*=2
    print(0,0)
    print(a,0)
    print(0,b)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    flag=0
    print('YES')
    if k%2==0:
        k//=2
        flag=1
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    if flag==0:
        if a<n:
            a*=2
        else:
            b*=2
    print(0,0)
    print(a,0)
    print(0,b)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    flag=0
    print('YES')
    if k%2==0:
        k//=2
        flag=1
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    if flag:
        if a<n:
            a*=2
        else:
            b*=2
    print(0,0)
    print(a,0)
    print(0,b)


def nod(a,b):
    while a*b!=0:
        if a>b:
            a%=b
        else:
            b%=a
    return a+b
n,m,k=map(int,input().split())
if 2*n*m%k!=0:
    print('NO')
else:
    print('YES')
    g=nod(n,k)
    ks=k//g
    a=n//g
    b=m//ks
    if a<n:
        a*=2
    else:
        b*=2
    print(0,0)
    print(a,0)
    print(0,b)


def gcd(a,b):
    if(a==0):
        return b
    return gcd(b%a,a)

n,m,k = map(int,input().split())
flag = 1
if(k%2==0):
    flag = k%2
    k=k//2
if(n*m)%k!=0:
    print("NO")
else:
    s = gcd(n,k)
    k = k//s
    a = n//s
    s = gcd(m,k)
    k = k//s
    b = m//s
    if(flag == 1):
        if(a<n):
            a+=a
        else:
            b+=b
    print("YES")
    print("0 0")
    print(a,"0")
    print("0",b)
# PRIYANHSU KUMAR
# Miles to go before i sleep :->>


def gcd(a,b):
    if(a==0):
        return b
    return gcd(b%a,a)

n,m,k = map(int,input().split())
flag = 1
if(k%2==0):
    flag = k%2
    k=k//2
if(n*m)%k!=0:
    print("NO")
else:
    s = gcd(n,k)
    a=n//s
    k=k//s
    b=m//k
    if(flag == 1):
        if(a<n):
            a+=a
        else:
            b+=b
    print("YES")
    print("0 0")
    print(a,"0")
    print("0",b)
# PRIYANHSU KUMAR
# Miles to go before i sleep :->>


n,m,k=map(int,input().split())
if (n*m)/k-(n*m)//k!=0 and (n*m)/k-(n*m)//k!=0.5:
    print("NO")
else:
    a=int(((n*m)/k)*2)
    x,y=-1,-1
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            if i<=n and a//i<=m:
                if i%2==0:
                    x=i
                    y=a//i
                    print("YES")
                    print(0,0)
                    print(x,0)
                    print(x//2,y)
                    break
                if (a//i)%2==0:
                    x=i
                    y=(a//i)
                    print("YES")
                    print(0,0)
                    print(0,y)
                    print(x,y//2)
                    break
            elif i<=m and a//i<=n:
                if (a//i)%2==0:
                    x=a//i
                    y=i
                    print("YES")
                    print(0,0)
                    print(x,0)
                    print(x//2,y)
                    break
                if i%2==0:
                    x=a//i
                    y=i
                    print("YES")
                    print(0,0)
                    print(0,y)
                    print(x,y//2)
                    break

    if x==-1:
        print("NO")


n,m,k=map(int,input().split())
from math import gcd
if (n*m)/k-(n*m)//k!=0 and (n*m)/k-(n*m)//k!=0.5:
    print("NO")
else:
    a=2*n
    b=2*m
    g1=gcd(a,k)
    g2=gcd(b,k)
    x=a//g1
    y=m//(k//g1)
    c=b//g2
    d=n//(k//g2)
    if x<=n and y<=m:
        print("YES")
        print(0,0)
        print(x,0)
        print(0,y)
    elif x<=m and y<=n:
        print("YES")
        print(0,0)
        print(y,0)
        print(0,x)
    elif c<=n and d<=m:
        print("YES")
        print(0,0)
        print(c,0)
        print(0,d)
    elif c<=m and d<=n:
        print("YES")
        print(0,0)
        print(d,0)
        print(0,c)
    else:
        print("NO")


n,m,k=map(int,input().split())
if (n*m)/k-(n*m)//k!=0 and (n*m)/k-(n*m)//k!=0.5:
    print("NO")
else:
    print("YES")
    a=int(((n*m)/k)*2)
    print(0,0)
    print(1,0)
    print(0,a)


import sys
n,m,k=map(int,input().split())
if (2*n*m)%k==0:
    s=set()
    f=0
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            s.add(i)
            s.add(n//i)
    s.add(n)
    s1=set()
    for i in range(2,int(m**0.5)+1):
        if m%i==0:
            s1.add(i)
            s1.add(m//i)
        #print(s1)
    s1.add(m)
    if m==1:
        if n%k==0:
            print("YES")
            print(0,0)
            print(2*n//k,0)
            print(0,1)
            sys.exit()
    elif n==1:
        if m%k==0:
            print("YES")
            print(0,0)
            print(1,0)
            print(0,2*m//k)
            sys.exit()
    #print(s,s1)
    for i in s:
        if k%i==0 and k//i in s1:
            print("YES")
            print(0,0)
            print(n//i,0)
            print(0,(2*m)//(k//i))
            f=1
            break
        elif k%(2*i)==0 and k//(2*i) in s1:
            print("YES")
            print(0,0)
            print(n//i,0)
            print(0,(2*m)//(k//i))
            f=1
            break
    if f==0:
        s.remove(1)
        s1.add(1)
        #print(s,s1)
        for i in s1:
           if k%i==0 and k//i in s:
            print("YES")
            print(0,0)
            print(0,m//i)
            print((2*n)//(k//i),0)
            f=1
            break
           elif k%(2*i)==0 and k//(2*i) in s:
            print("YES")
            print(0,0)
            print(0,m//i)
            print((2*n)//(k//i),0)
            f=1
            break
        if f==0:
            print("NO")

else:
    print("NO")


// by redleaf23477
#include <bits/stdc++.h>

// iostream macros
#define endl '\n'
#define var(x) "[" << #x << "=" << x << "]"
// chrono macros
#define chrono_now std::chrono::high_resolution_clock::now()
#define chrono_duration(t1, t2) std::chrono::duration<double>(t2-t1).count()
#define chrono_rand_seed chrono_now.time_since_epoch().count()
// random
std::mt19937_64 myrand(chrono_rand_seed);

using namespace std;
using LL = long long int;

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    for(int t = 1; t <= T; t++)
    {
        init();
        process();
    }
    cout.flush();
    return 0;
}

vector<pair<int,int>> robot, light;

void init()
{
    int n, m; cin >> n >> m;
    vector<pair<int,int>> rob(n), lig(m);
    for(auto &r : rob) cin >> r.first >> r.second;
    for(auto &l : lig) cin >> l.first >> l.second;
    /*
    sort(rob.begin(), rob.end());
    sort(lig.begin(), lig.end());

    for(auto r : rob)
    {
        while(!robot.empty() && r.second >= robot.back().second)
            robot.pop_back();
        robot.emplace_back(r);
    }

    for(auto l : lig)
    {
        if(light.empty() || l.second < light.back().second)
            light.emplace_back(l);
    }
    */
    light = lig, robot = rob;
}

void process()
{
    vector<int> ans(1000006, 0);

    for(auto r : robot) for(auto l : light)
    {
        int dx = l.first - r.first;
        int dy = max(0, l.second + 1 - r.second);
        if(dx >= 0) ans[dx] = max(ans[dx], dy);
    }

    for(int i = ans.size()-2; i >= 0; i--) ans[i] = max(ans[i], ans[i+1]);

    int ans2 = 2000006;
    for(int i = 0; i < (int)ans.size(); i++) ans2 = min(ans2, i+ans[i]);
    cout << ans2 << endl;
}


// by redleaf23477
#include <bits/stdc++.h>

// iostream macros
#define endl '\n'
#define var(x) "[" << #x << "=" << x << "]"
// chrono macros
#define chrono_now std::chrono::high_resolution_clock::now()
#define chrono_duration(t1, t2) std::chrono::duration<double>(t2-t1).count()
#define chrono_rand_seed chrono_now.time_since_epoch().count()
// random
std::mt19937_64 myrand(chrono_rand_seed);

using namespace std;
using LL = long long int;

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    for(int t = 1; t <= T; t++)
    {
        init();
        process();
    }
    cout.flush();
    return 0;
}

vector<pair<int,int>> robot, light;

void init()
{
    int n, m; cin >> n >> m;
    vector<pair<int,int>> rob(n), lig(m);
    for(auto &r : rob) cin >> r.first >> r.second;
    for(auto &l : lig) cin >> l.first >> l.second;
    sort(rob.begin(), rob.end());
    sort(lig.begin(), lig.end());

    /*
    for(auto r : rob)
    {
        while(!robot.empty() && r.second >= robot.back().second)
            robot.pop_back();
        robot.emplace_back(r);
    }
    */

    for(auto l : lig)
    {
        if(light.empty() || l.second < light.back().second)
            light.emplace_back(l);
    }
    light = lig, robot = rob;
}

void process()
{
    vector<int> ans(1000006, 0);

    for(auto r : robot) for(auto l : light)
    {
        int dx = l.first - r.first;
        int dy = max(0, l.second + 1 - r.second);
        if(dx >= 0) ans[dx] = max(ans[dx], dy);
    }

    for(int i = ans.size()-2; i >= 0; i--) ans[i] = max(ans[i], ans[i+1]);

    int ans2 = 2000006;
    for(int i = 0; i < (int)ans.size(); i++) ans2 = min(ans2, i+ans[i]);
    cout << ans2 << endl;
}


// by redleaf23477
#include <bits/stdc++.h>

// iostream macros
#define endl '\n'
#define var(x) "[" << #x << "=" << x << "]"
// chrono macros
#define chrono_now std::chrono::high_resolution_clock::now()
#define chrono_duration(t1, t2) std::chrono::duration<double>(t2-t1).count()
#define chrono_rand_seed chrono_now.time_since_epoch().count()
// random
std::mt19937_64 myrand(chrono_rand_seed);

using namespace std;
using LL = long long int;

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    for(int t = 1; t <= T; t++)
    {
        init();
        process();
    }
    cout.flush();
    return 0;
}

vector<pair<int,int>> robot, light;

bool cmp(const pair<int,int> &lhs, const pair<int,int> &rhs)
{
    if(lhs.first != rhs.first) return lhs.first < rhs.first;
    else return lhs.second < rhs.second;
}

void init()
{
    int n, m; cin >> n >> m;
    vector<pair<int,int>> rob(n), lig(m);
    for(auto &r : rob) cin >> r.first >> r.second;
    for(auto &l : lig) cin >> l.first >> l.second;
    sort(rob.begin(), rob.end(), cmp);
    sort(lig.begin(), lig.end(), cmp);

    for(auto r : rob)
    {
        while(!robot.empty() && r.second >= robot.back().second)
            robot.pop_back();
        robot.emplace_back(r);
    }

    /*
    for(auto l : lig)
    {
        if(light.empty() || l.second < light.back().second)
            light.emplace_back(l);
    }
    */

    light = lig;
}

void process()
{
    vector<int> ans(1000006, 0);

    for(auto r : robot) for(auto l : light)
    {
        int dx = l.first - r.first;
        int dy = max(0, l.second + 1 - r.second);
        if(dx >= 0) ans[dx] = max(ans[dx], dy);
    }

    for(int i = ans.size()-2; i >= 0; i--) ans[i] = max(ans[i], ans[i+1]);

    int ans2 = 2000006;
    for(int i = 0; i < (int)ans.size(); i++) ans2 = min(ans2, i+ans[i]);
    cout << ans2 << endl;
}


// by redleaf23477
#include <bits/stdc++.h>

// iostream macros
#define endl '\n'
#define var(x) "[" << #x << "=" << x << "]"
// chrono macros
#define chrono_now std::chrono::high_resolution_clock::now()
#define chrono_duration(t1, t2) std::chrono::duration<double>(t2-t1).count()
#define chrono_rand_seed chrono_now.time_since_epoch().count()
// random
std::mt19937_64 myrand(chrono_rand_seed);

using namespace std;
using LL = long long int;

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    for(int t = 1; t <= T; t++)
    {
        init();
        process();
    }
    cout.flush();
    return 0;
}

vector<pair<int,int>> robot, light;

void init()
{
    int n, m; cin >> n >> m;
    vector<pair<int,int>> rob(n), lig(m);
    for(auto &r : rob) cin >> r.first >> r.second;
    for(auto &l : lig) cin >> l.first >> l.second;
    sort(rob.begin(), rob.end());
    sort(lig.begin(), lig.end());

    for(auto r : rob)
    {
        while(!robot.empty() && r.second >= robot.back().second)
            robot.pop_back();
        robot.emplace_back(r);
    }

    for(auto l : lig)
    {
        if(light.empty() || l.second < light.back().second)
            light.emplace_back(l);
    }
}

void process()
{
    vector<int> h(2000000, -1);
    for(auto l : light) h[l.first] = l.second;
    for(int i = h.size()-2; i >= 0; i--) h[i] = max(h[i], h[i+1]);

    vector<int> ans(1000006, 0);

    for(auto r : robot) for(auto l : light)
    {
        int dx = l.first - r.first;
        int dy = max(0, l.second + 1 - r.second);
        if(dx >= 0) ans[dx] = max(ans[dx], dy);
    }

    for(int i = ans.size()-2; i >= 0; i--) ans[i] = max(ans[i], ans[i+1]);

    int ans2 = 2000006;
    for(int i = 0; i < (int)ans.size(); i++) ans2 = min(ans2, i+ans[i]);
    cout << ans2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(numRight<=maxRight+10){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=max(searchlights[m-1].first+1-robbers[0].first,0ll);
    ll ans=maxRight;

    ll numRight=0;

    ll whereTo[m];
    ll currWhere=m-1;
    whereTo[m-1]=m-1;
    for(int i=m-2;i>=0;i--){
    	if(suffixMaxY[i]!=suffixMaxY[i+1]){
    		currWhere=i;
    	}
    	whereTo[i]=currWhere;
    }

    while(numRight<=maxRight){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
    			ll temp = suffixMaxY[searchlightsPointer]+1-robbers[j].second;
    			if(temp>howManyUp){
		    		howManyUp=max(howManyUp,temp);
		    		// get where to go
		    		// cerr<<searchlightsPointer<<" "<<whereTo[searchlightsPointer]<<endl;
		    		nextJump=min(nextJump,searchlights[whereTo[searchlightsPointer]].first+1-robbers[j].first-numRight);
    			}
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	nextJump=max(nextJump,1ll);
    	// if(numRight>maxRight)break;
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(numRight<=3*maxRight){

    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX/2;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	nextJump=max(nextJump,1ll);
    	// if(numRight>maxRight)break;
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(numRight<=maxRight){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(true){

    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX/2;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	numRight=max(numRight,1ll);
    	if(numRight>maxRight)break;
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=INT_MAX;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(true){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(true){

    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX/2;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	nextJump=max(nextJump,1ll);
    	// if(numRight>maxRight)break;
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=searchlights[m-1].first+1-robbers[0].first;
    ll ans=INT_MAX;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    int numRight=0;
    while(numRight<=maxRight){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	int searchlightsPointer=0;
    	ll nextJump=INT_MAX;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=max(searchlights[m-1].first+1-robbers[0].first,0ll);
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(numRight<=maxRight){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	nextJump=max(nextJump,1ll);
    	// if(numRight>maxRight)break;
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

typedef pair<ll,ll> intpair;

int main(){

	#ifndef ONLINE_JUDGE
    	freopen("input", "r", stdin);
      //to check for segfault in sublime, uncomment the following line
    	freopen("output", "w", stdout);
    	freopen("error", "w", stderr);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,m;
    cin>>n>>m;

    vector<intpair> robbers(n);
    vector<intpair> searchlights(m);

    intpair temp;
    for(int i=0;i<n;i++){
    	cin>>temp.first>>temp.second;
    	robbers[i]=temp;
    }

    for(int i=0;i<m;i++){
    	cin>>temp.first>>temp.second;
    	searchlights[i]=temp;
    }

    sort(robbers.begin(), robbers.end());
    sort(searchlights.begin(), searchlights.end());

    // at each x, compute what the minimum safe y is
    ll suffixMaxY[m];
    suffixMaxY[m-1]=searchlights[m-1].second;
    for(int i=m-2;i>=0;i--){
    	suffixMaxY[i]=max(searchlights[i].second, suffixMaxY[i+1]);
    }

    ll maxRight=max(searchlights[m-1].first+1-robbers[0].first,0ll);
    ll ans=maxRight;

    // for(int i=0;i<n;i++){
    // 	cerr<<robbers[i].first<<" "<<robbers[i].second<<endl;
    // }

    // for(int i=0;i<m;i++){
    // 	cerr<<searchlights[i].first<<" "<<searchlights[i].second<<endl;
    // }

    ll numRight=0;
    while(numRight<=maxRight){
    	// cerr<<numRight<<endl;
    	ll howManyUp=0;
    	ll searchlightsPointer=0;
    	ll nextJump=INT_MAX/2;
    	for(int j=0;j<n;j++){
    		while(searchlightsPointer<m && searchlights[searchlightsPointer].first<robbers[j].first+numRight){
    			searchlightsPointer++;
    		}
    		// cerr<<searchlightsPointer<<endl;
    		if(searchlightsPointer<m){
	    		nextJump=min(nextJump,searchlights[searchlightsPointer].first+1-robbers[j].first-numRight);
	    		howManyUp=max(howManyUp,suffixMaxY[searchlightsPointer]+1-robbers[j].second);
	    	}
	    	// cerr<<j<<" "<<nextJump<<endl;
    	}
    	ans=min(ans,numRight+howManyUp);
    	nextJump=max(nextJump,1ll);
    	// if(numRight>maxRight)break;
    	if(nextJump==INT_MAX)break;
    	numRight+=nextJump;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int mx[2000010];
int res=1e9;
vector<int> v,vt[1000010];
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	sort(a,a+n),sort(b,b+n),reverse(a,a+n),reverse(b,b+n);
	int t=-1,ti=0;
	for (int i=2*len;i>=0;i--)
	{
		while (i<=b[ti].Fst && ti<m) t=max(t,(ti==m ? -1 : b[ti].Snd)),ti++;
		mx[i]=t+1;
	}
	for (int i=0;i<=2*len;i++) if (mx[i]!=mx[i+1]) v.push_back(i+1);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<v.size();j++)
		{
			if (a[i].Fst>=v[j]) continue;
			vt[v[j]-a[i].Fst].push_back(i);
		}
	}
	//for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	//cout <<"\n";
	multiset<int> st;
	for (int i=0;i<=len;i++)
	{
		//cout <<i<<" "<<vt[i].size()<<" ##################\n";
		if (!i)
		{
			for (int j=0;j<n;j++)
			{
				if (a[j].Fst+i<=len)
					st.insert(-max(0,mx[a[j].Fst+i]-a[j].Snd));
			}
		}
		else
		{
			for (int j=0;j<vt[i].size();j++)
			{
				int x=vt[i][j];
				multiset<int>::iterator it=st.lower_bound(-max(0,mx[a[x].Fst+i-1]-a[x].Snd));
				st.erase(it);
				st.insert(-max(0,mx[a[x].Fst+i]-a[x].Snd));
			}
		}
		//cout <<i<<" "<<-*st.begin()<<" ###########\n";
		res=min(res,i-*st.begin());
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int seg[8000010],mx[1000010];
int res=1e9;
void into(int t,int l,int r,int li,int ri,int val)
{
	if (r<li || ri<l) return;
	if (li<=l && r<=ri)
	{
		seg[t]=max(seg[t],val);
		return;
	}
	int mid=(l+r)>>1;
	into(t*2,l,mid,li,ri,val),into(t*2+1,mid+1,r,li,ri,val);
}
int getmax(int t,int l,int r,int pos)
{
	if (l==r && l==pos) return seg[t];
	int mid=(l+r)>>1;
	if (pos<=mid) return max(seg[t],getmax(t*2,l,mid,pos));
	else return max(seg[t],getmax(t*2+1,mid+1,r,pos));
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	memset(seg,-1,sizeof(seg));
	for (int i=0;i<m;i++) into(1,0,len,0,b[i].Fst,b[i].Snd);
	for (int i=0;i<=len;i++) mx[i]=getmax(1,0,len,i)+1;
	//for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	//cout <<"\n";
	for (int i=0;i<=len;i++)
	{
		int r=0;
		bool fl=0;
		for (int j=0;j<n;j++)
		{
			if (a[j].Fst+i<=len)
			{
				r=max(r,max(0,mx[a[j].Fst+i]-a[j].Snd));
				//cout <<j<<" "<<max(0,mx[a[j].Fst+i]-a[j].Snd)<<" ##\n";
				if (mx[a[j].Fst+i]) fl=1;
				else break;
			}
		}
		//cout <<i<<" "<<r<<" ###########\n";
		res=min(res,i+r);
		if (!fl) break;
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int mx[2000010];
int res=1e9;
vector<int> v,vt[1000010];
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	sort(a,a+n),sort(b,b+m),reverse(a,a+n),reverse(b,b+m);
	int t=-1,ti=0;
	for (int i=2*len;i>=0;i--)
	{
		while (i<=b[ti].Fst && ti<m) t=max(t,(ti==m ? -1 : b[ti].Snd)),ti++;
		mx[i]=t+1;
	}
	for (int i=0;i<=2*len;i++) if (mx[i]!=mx[i+1]) v.push_back(i+1);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<v.size();j++)
		{
			if (a[i].Fst>=v[j]) continue;
			vt[v[j]-a[i].Fst].push_back(i);
		}
	}
	//for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	//cout <<"\n";
	multiset<int> st;
	for (int i=0;i<=len;i++)
	{
		//cout <<i<<" "<<vt[i].size()<<" ##################\n";
		if (!i)
		{
			for (int j=0;j<n;j++)
			{
				if (a[j].Fst+i<=len)
					st.insert(-max(0,mx[a[j].Fst+i]-a[j].Snd));
			}
		}
		else
		{
			for (int j=0;j<vt[i].size();j++)
			{
				int x=vt[i][j];
				multiset<int>::iterator it=st.lower_bound(-max(0,mx[a[x].Fst+i-1]-a[x].Snd));
				st.erase(it);
				st.insert(-max(0,mx[a[x].Fst+i]-a[x].Snd));
			}
		}
		//cout <<i<<" "<<-*st.begin()<<" ###########\n";
		res=min(res,i-*st.begin());
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int seg[8000010],mx[2000010];
int res=1e9;
void into(int t,int l,int r,int li,int ri,int val)
{
	if (r<li || ri<l) return;
	if (li<=l && r<=ri)
	{
		seg[t]=max(seg[t],val);
		return;
	}
	int mid=(l+r)>>1;
	into(t*2,l,mid,li,ri,val),into(t*2+1,mid+1,r,li,ri,val);
}
int getmax(int t,int l,int r,int pos)
{
	if (l==r && l==pos) return seg[t];
	int mid=(l+r)>>1;
	if (pos<=mid) return max(seg[t],getmax(t*2,l,mid,pos));
	else return max(seg[t],getmax(t*2+1,mid+1,r,pos));
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	memset(seg,-1,sizeof(seg));
	for (int i=0;i<m;i++) into(1,0,len,0,b[i].Fst,b[i].Snd);
	for (int i=0;i<=len;i++) mx[i]=getmax(1,0,len,i)+1;
	//for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	//cout <<"\n";
	int r=0;
	for (int i=0;i<=len;i++)
	{
		bool fl=0;
		if (!i)
		{
			for (int j=0;j<n;j++)
			{
				if (a[j].Fst+i<=len)
				{
					r=max(r,max(0,mx[a[j].Fst+i]-a[j].Snd));
					//cout <<j<<" "<<max(0,mx[a[j].Fst+i]-a[j].Snd)<<" ##\n";
					if (mx[a[j].Fst+i]) fl=1;
					else break;
				}
			}
		}
		else
		{
			for (int j=0;j<n;j++)
			{
				if (mx[a[j].Fst+i-1]!=mx[a[j].Fst+i])
					r=max(r,max(0,mx[a[j].Fst+i]-a[j].Snd));
			}
		}
		//cout <<i<<" "<<r<<" ###########\n";
		res=min(res,i+r);
		if (!fl) break;
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int seg[8000010],mx[2000010];
int res=1e9;
void into(int t,int l,int r,int li,int ri,int val)
{
	if (r<li || ri<l) return;
	if (li<=l && r<=ri)
	{
		seg[t]=max(seg[t],val);
		return;
	}
	int mid=(l+r)>>1;
	into(t*2,l,mid,li,ri,val),into(t*2+1,mid+1,r,li,ri,val);
}
int getmax(int t,int l,int r,int pos)
{
	if (l==r && l==pos) return seg[t];
	int mid=(l+r)>>1;
	if (pos<=mid) return max(seg[t],getmax(t*2,l,mid,pos));
	else return max(seg[t],getmax(t*2+1,mid+1,r,pos));
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	memset(seg,-1,sizeof(seg));
	for (int i=0;i<m;i++) into(1,0,len,0,b[i].Fst,b[i].Snd);
	for (int i=0;i<=len;i++) mx[i]=getmax(1,0,len,i)+1;
	//for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	//cout <<"\n";
	int r=0;
	for (int i=0;i<=len;i++)
	{
		bool fl=0;
		if (!i)
		{
			for (int j=0;j<n;j++)
			{
				if (a[j].Fst+i<=len)
				{
					r=max(r,max(0,mx[a[j].Fst+i]-a[j].Snd));
					//cout <<j<<" "<<max(0,mx[a[j].Fst+i]-a[j].Snd)<<" ##\n";
					if (mx[a[j].Fst+i]) fl=1;
					else break;
				}
			}
		}
		else
		{
			for (int j=0;j<n;j++)
			{
				if (mx[a[j].Fst+i-1]!=mx[a[j].Fst+i])
					r+=mx[a[j].Fst+i]-mx[a[j].Fst+i-1];
			}
		}
		//cout <<i<<" "<<r<<" ###########\n";
		res=min(res,i+r);
		if (!fl) break;
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int seg[8000010],mx[1000010];
int res=1e9;
void into(int t,int l,int r,int li,int ri,int val)
{
	if (r<li || ri<l) return;
	if (li<=l && r<=ri)
	{
		seg[t]=max(seg[t],val);
		return;
	}
	int mid=(l+r)>>1;
	into(t*2,l,mid,li,ri,val),into(t*2+1,mid+1,r,li,ri,val);
}
int getmax(int t,int l,int r,int pos)
{
	if (l==r && l==pos) return seg[t];
	int mid=(l+r)>>1;
	if (pos<=mid) return max(seg[t],getmax(t*2,l,mid,pos));
	else return max(seg[t],getmax(t*2+1,mid+1,r,pos));
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	memset(seg,-1,sizeof(seg));
	for (int i=0;i<m;i++) into(1,0,len,0,b[i].Fst,b[i].Snd);
	for (int i=0;i<=len;i++) mx[i]=getmax(1,0,len,i)+1;
	//for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	//cout <<"\n";
	for (int i=0;i<=len;i++)
	{
		int r=0;
		bool fl=0;
		for (int j=0;j<n;j++)
		{
			if (a[j].Fst+i<=len)
			{
				r=max(r,max(0,mx[a[j].Fst+i]-a[j].Snd));
				//cout <<j<<" "<<max(0,mx[a[j].Fst+i]-a[j].Snd)<<" ##\n";
				if (mx[a[j].Fst+i]>1) fl=1;
			}
		}
		//cout <<i<<" "<<r<<" ###########\n";
		res=min(res,i+r);
		if (!fl) break;
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int seg[8000010],mx[2000010];
int res=1e9;
void into(int t,int l,int r,int li,int ri,int val)
{
	if (r<li || ri<l) return;
	if (li<=l && r<=ri)
	{
		seg[t]=max(seg[t],val);
		return;
	}
	int mid=(l+r)>>1;
	into(t*2,l,mid,li,ri,val),into(t*2+1,mid+1,r,li,ri,val);
}
int getmax(int t,int l,int r,int pos)
{
	if (l==r && l==pos) return seg[t];
	int mid=(l+r)>>1;
	if (pos<=mid) return max(seg[t],getmax(t*2,l,mid,pos));
	else return max(seg[t],getmax(t*2+1,mid+1,r,pos));
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	memset(seg,-1,sizeof(seg));
	for (int i=0;i<m;i++) into(1,0,len,0,b[i].Fst,b[i].Snd);
	for (int i=0;i<=len;i++) mx[i]=getmax(1,0,len,i)+1;
	/*for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	cout <<"\n";*/
	set<int> st;
	int r=0;
	for (int i=0;i<=len;i++)
	{
		if (!i)
		{
			for (int j=0;j<n;j++)
			{
				if (a[j].Fst+i<=len)
					st.insert(-max(0,mx[a[j].Fst+i]-a[j].Snd));
			}
		}
		else
		{
			for (int j=0;j<n;j++)
			{
				if (mx[a[j].Fst+i-1]!=mx[a[j].Fst+i])
				{
					st.erase(-max(0,mx[a[j].Fst+i-1]-a[j].Snd));
					st.insert(-max(0,mx[a[j].Fst+i]-a[j].Snd));
				}
			}
		}
		//cout <<i<<" "<<r<<" ###########\n";
		res=min(res,i-*st.begin());
	}
	cout <<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
#define len 1000000
using namespace std;
int n,m;
PII a[2010],b[2010];
int seg[8000010],mx[2000010];
int res=1e9;
vector<int> v,vt[1000010];
void into(int t,int l,int r,int li,int ri,int val)
{
	if (r<li || ri<l) return;
	if (li<=l && r<=ri)
	{
		seg[t]=max(seg[t],val);
		return;
	}
	int mid=(l+r)>>1;
	into(t*2,l,mid,li,ri,val),into(t*2+1,mid+1,r,li,ri,val);
}
int getmax(int t,int l,int r,int pos)
{
	if (l==r && l==pos) return seg[t];
	int mid=(l+r)>>1;
	if (pos<=mid) return max(seg[t],getmax(t*2,l,mid,pos));
	else return max(seg[t],getmax(t*2+1,mid+1,r,pos));
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i].Fst>>a[i].Snd;
	for (int i=0;i<m;i++) cin >>b[i].Fst>>b[i].Snd;
	memset(seg,-1,sizeof(seg));
	for (int i=0;i<m;i++) into(1,0,len,0,b[i].Fst,b[i].Snd);
	for (int i=0;i<=len;i++) mx[i]=getmax(1,0,len,i)+1;
	for (int i=0;i<=2*len;i++) if (mx[i]!=mx[i+1]) v.push_back(i+1);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<v.size();j++)
		{
			if (a[i].Fst>=v[j]) continue;
			vt[v[j]-a[i].Fst].push_back(i);
		}
	}
	/*for (int i=0;i<=20;i++) cout <<mx[i]<<" ";
	cout <<"\n";*/
	multiset<int> st;
	int r=0;
	for (int i=0;i<=len;i++)
	{
		//cout <<i<<" "<<vt[i].size()<<" ##################\n";
		if (!i)
		{
			for (int j=0;j<n;j++)
			{
				if (a[j].Fst+i<=len)
					st.insert(-max(0,mx[a[j].Fst+i]-a[j].Snd));
			}
		}
		else
		{
			for (int j=0;j<vt[i].size();j++)
			{
				int x=vt[i][j];
				multiset<int>::iterator it=st.lower_bound(-max(0,mx[a[x].Fst+i-1]-a[x].Snd));
				st.erase(it);
				st.insert(-max(0,mx[a[x].Fst+i]-a[x].Snd));
			}
		}
		//cout <<i<<" "<<r<<" ###########\n";
		res=min(res,i-*st.begin());
	}
	cout <<res;
	return 0;
}


#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e4;
//constexpr ll MOD=1e5;
constexpr ll MAX=3e6;
constexpr ll inf=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template<typename T>
struct Segment_tree{
    ll N;
    T mem;
    vector<T> node;
    Segment_tree(vector<T> &X,T m):mem(m){
        ll sz=X.size();
        N=1;
        while(N<sz) N*=2;
        node.resize(2*N-1,mem);
        rep(i,0,sz) node[N-1+i]=X[i];
        per(i,N-2,0){
            node[i]=Compare(node[i*2+1],node[i*2+2]);
        }
    }
    T Compare(T &A,T &B){
        return std::min(A,B);
    }
    void update(ll X,T val){
        X+=N-1;
        node[X]=val;
        while(X>0){
            X=(X-1)/2;
            node[X]=Compare(node[X*2+1],node[X*2+2]);
        }
    }
    T Query(ll a,ll b,ll now=0,ll l=0,ll r=-1){ //[a,b),[l,r)
        if(r<0) r=N;
        if(r<=a||b<=l) return mem;
        if(a<=l&&r<=b) return node[now];
        auto vl=Query(a,b,now*2+1,l,(l+r)/2),vr=Query(a,b,now*2+2,(l+r)/2,r);
        return Compare(vl,vr);
    }
    ll lower_bound(ll left,ll right,T val,ll now=0,ll l=0,ll r=-1){
        if(r<0) r=N;
        if(node[now]<val||l>=right||left>=r) return r;
        else if(now>=N-1) return l;
        ll vl=lower_bound(left,right,val,now*2+1,l,(l+r)/2);
        if(vl==(l+r)/2) return lower_bound(left,right,val,now*2+2,(l+r)/2,r);
        return vl;
    }
};
template<typename T>
struct lazy_Segment_tree{
    int N;
    vector<T> node,lazy;
    T INF;
    vector<bool> flag;
    lazy_Segment_tree(vector<T> X,T Y):INF(Y){
        N=1;
        while(X.size()>N) N*=2;
        node.resize(2*N-1,Y);
        lazy.resize(2*N-1);
        flag.resize(2*N-1);
        rep(i,0,X.size()) node[i+N-1]=X[i];
        per(i,N-2,0) node[i]=compare(node[i*2+1],node[i*2+2]);
    }
    T compare(T X,T Y){
        return std::max(X,Y);
    }
    T plus(T X,int l,int r){
        return X;
    }
    void eval(int now,int l,int r){
        if(flag[now]){
            if(r-l>1){
                flag[now*2+1]=flag[now*2+2]=1;
                lazy[now*2+1]=lazy[now*2+2]=lazy[now];
            }
            node[now]=lazy[now];
            flag[now]=0;
        }
    }
    void update(int a,int b,T add,int now=0,int l=0,int r=-1){
        if(r<0) r=N;
        eval(now,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            lazy[now]=add;
            flag[now]=1;
            eval(now,l,r);
        }
        else{
            update(a,b,add,now*2+1,l,(r+l)/2);
            update(a,b,add,now*2+2,(r+l)/2,r);
            node[now]=compare(node[now*2+1],node[now*2+2]);
        }
    }
    T Query(int a,int b,int now=0,int l=0,int r=-1){
        if(r<0) r=N;
        eval(now,l,r);
        if(b<=l||r<=a) return INF;
        if(a<=l&&r<=b) return node[now];
        return compare(Query(a,b,now*2+1,l,(r+l)/2),Query(a,b,now*2+2,(r+l)/2,r));
    }
    ll lower_bound(ll left,ll right,T val,ll now=0,ll l=0,ll r=-1){
        eval(now,l,r);
        if(r<0) r=N;
        if(node[now]<val||l>=right||left>=r) return r;
        else if(now>=N-1) return l;
        ll vl=lower_bound(left,right,val,now*2+1,l,(l+r)/2);
        if(vl==(l+r)/2) return lower_bound(left,right,val,now*2+2,(l+r)/2,r);
        return vl;
    }
};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,ll a){
        x++;
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        x++;
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
    ll lower_bound(ll X){
        if(sum(N)<X) return -1;
        ll ret=0,memo=1,sum=0;
        while(memo*2<=N) memo*=2;
        while(memo>0){
            if(memo+ret<=N&&sum+bit[memo+ret]<X){
                sum+=bit[memo+ret];
                ret+=memo;
            }
            memo/=2;
        }
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        if(siz[Y]<siz[X]) std::swap(X,Y);
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
struct Strongly_Connected_Components{
    ll N,M;
    vii edge,ver;
    vi ind;
    Strongly_Connected_Components(vii e){
        ll n=e.size();
        ll m=0;
        vii revedge(n);
        ind.resize(n);
        rep(i,0,n){
            m+=e[i].size();
            for(auto p:e[i]) revedge[p].pb(i);
        }
        vi num(n,-1),po(n);
        vector<bool> seen(n);
        ll cnt=0;
        rep(i,0,n){
            if(num[i]==-1){
                dfs(i,e,num,cnt);
            }
        }
        rep(i,0,n) po[num[i]]=i;
        per(i,n-1,0){
            ll X=po[i];
            if(!seen[X]){
                std::queue<ll> que;
                vi v;
                que.push(X);
                seen[X]=1;
                while(!que.empty()){
                    ll now=que.front(); que.pop();
                    v.pb(now);
                    ind[now]=ver.size();
                    for(auto p:revedge[now]){
                        if(!seen[p]){
                            seen[p]=1;
                            que.push(p);
                        }
                    }
                }
                ver.pb(v);
            }
        }
        N=ver.size();
        M=0;
        edge.resize(N);
        rep(i,0,n){
            for(auto p:e[i]){
                if(ind[i]==ind[p]) continue;
                M++;
                edge[ind[i]].pb(ind[p]);
            }
        }
    }
    void dfs(ll now,vii &e,vi &num,ll &cnt){
        num[now]=0;
        for(auto next:e[now]){
            if(num[next]==-1){
                dfs(next,e,num,cnt);
            }
        }
        num[now]=cnt++;
    }
};
struct lowlink{
    ll N;
    vii edge;
    vi ord,low,aps;
    vector<bool> used;
    vector<pii> bridges;
    lowlink(vii e):edge(e){
        N=edge.size();
        used.resize(N);
        ord.resize(N);
        low.resize(N);
        ll cnt=0;
        rep(i,0,N){
            if(!used[i]) dfs(i,cnt,-1);
        }
    }
    void dfs(ll now,ll &cnt,ll from){
        used[now]=1;
        ord[now]=cnt++;
        low[now]=ord[now];
        bool flag=0;
        for(auto next:edge[now]){
            if(!used[now]){
                dfs(next,cnt,now);
                low[now]=std::min(low[now],low[next]);
                if(from!=-1&&ord[now]<=low[next]) flag=1;
                if(ord[now]<low[next]) bridges.pb(mp(now,next));
            }
            else if(next!=from) low[now]=std::min(low[now],ord[next]);
        }
        if(from==-1&&edge[now].size()>=2) flag=1;
        if(flag) aps.pb(now);
    }
};
struct Directed_Gragh{
    ll N,M;
    vii edge;
    Directed_Gragh(vii e):edge(e){
        N=edge.size();
        rep(i,0,N) M+=edge[i].size();
    }
    vi sort(){
        vi ret;
        vi cnt(N);
        rep(i,0,N){
            for(auto p:edge[i]) cnt[p]++;
        }
        std::queue<ll> que;
        rep(i,0,N){
            if(cnt[i]==0) que.push(i);
        }
        while(!que.empty()){
            ll now=que.front(); que.pop();
            ret.pb(now);
            for(auto next:edge[now]){
                cnt[next]--;
                if(cnt[next]==0) que.push(next);
            }
        }
        return ret;
    }
};
struct Tree{
    int N;
    vii dp;
    vi par;
    vi dist;
    vi subtree;
    vii edge;
    Tree(vii E):edge(E){
        N=edge.size();
        dp.resize(N);
        par.resize(N);
        dist.resize(N,-1);
        for(int i=0;i<N;i++) dp[i].resize(30);
        dist[0]=dp[0][0]=0;
        std::queue<int> que;
        que.push(0);
        while(!que.empty()){
            int now=que.front(); que.pop();
            for(int i=0;i<edge[now].size();i++){
                int next=edge[now][i];
                if(dist[next]==-1){
                    dist[next]=dist[now]+1;
                    que.push(next);
                    par[next]=now;
                    dp[next][0]=now;
                }
            }
        }
        for(int i=1;i<30;i++){
            for(int j=0;j<N;j++) dp[j][i]=dp[dp[j][i-1]][i-1];
        }
    }
    int LCA(int X,int Y){
        if(dist[X]<dist[Y]) std::swap(X,Y);
        {
            int Z=dist[X]-dist[Y];
            for(int i=0;i<30;i++){
                if(Z&(1<<i)){
                    X=dp[X][i];
                }
            }
        }
        if(X==Y) return X;
        for(int i=29;i>=0;i--){
            if(dp[X][i]!=dp[Y][i]){
                X=dp[X][i];
                Y=dp[Y][i];
            }
        }
        return dp[X][0];
    }
    void Subtree(){
        subtree.resize(N,-1);
        dfs(0);
    }
    void dfs(ll now){
        subtree[now]=1;
        for(auto next:edge[now]){
            if(subtree[next]==-1){
                dfs(next);
                subtree[now]+=subtree[next];
            }
        }
    }
};
template<typename T>
vi Declination_sort(ll N,T x,T y,vi X,vi Y){
    vi ret(N);
    vector<std::pair<long double,ll>> data(N);
    rep(i,0,N){
        long double A=X[i]-x,B=Y[i]-y;
        long double rad=atan2(B,A);
        data[i]=mp(rad,i);
    }
    sort(ALL(data));
    rep(i,0,N) ret[i]=data[i].second;
    return ret;
}
struct Convex_Hull{
    ll N;
    vi X,Y;
    Convex_Hull(vi A,vi B):X(A),Y(B){
        N=X.size();
        ll sx=0,sy=0;
        rep(i,0,N){
            sx+=X[i];
            sy+=Y[i];
        }
        double x=sx*1.0/N,y=sy*1.0/N;
        vi ind=Declination_sort<long double>(N,x,y,X,Y);
        vi C(N),D(N);
        rep(i,0,N){
            C[i]=X[ind[i]];
            D[i]=Y[ind[i]];
        }
        X=C;
        Y=D;
    }
    /*vi Find(){

    }*/
};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vi fac,finv,inv;
void COMinit() {
    fac.resize(MAX);
    finv.resize(MAX);
    inv.resize(MAX);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
void comp(vi &A){
    std::map<ll,ll> memo;
    rep(i,0,A.size()) memo[A[i]]=0;
    ll cnt=0;
    for(auto &p:memo) p.second=cnt++;
    rep(i,0,A.size()) A[i]=memo[A[i]];
}
void dec(std::map<ll,ll> &mem,ll X){
    mem[X]--;
    if(mem[X]==0) mem.erase(X);
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::random_device rnd;
    std::mt19937 mt(rnd());
    ll N,M; cin>>N>>M;
    vi A(N),B(N);
    rep(i,0,N) cin>>A[i]>>B[i];
    vector<pii> data(M);
    rep(i,0,M) cin>>data[i].first>>data[i].second;
    sort(ALL(data));
    {
        std::map<ll,ll> a;
        rep(i,0,M) a[data[i].first]=data[i].second;
        data.clear();
        for(auto p:a) data.pb(p);
        M=a.size();
    }
    std::map<ll,ll> cnt;
    vi mem(M);
    rep(i,0,M) cnt[data[i].second]++;
    rep(i,0,M){
        mem[i]=(*cnt.rbegin()).first+1;
        dec(cnt,data[i].second);
    }
    ll ans=inf;
    const ll max=2e6;
    vii record(max+1);
    rep(i,0,N){
        ll min=inf;
        rep(j,0,M){
            if(data[j].first>=A[i]){
                ll X=data[j].first-A[i];
                ll Y=0;
                if(j) Y=std::max(0ll,data[j-1].first+1-A[i]);
                ll Z=std::max(0ll,mem[j]-B[i]);
                record[X+1].pb(inf+Z);
                record[Y].pb(Z);
            }
        }
        ll X=std::max(0ll,data[M-1].first+1-A[i]);
        record[X].pb(0);
    }
    cnt.clear();
    REP(i,0,max){
        for(auto p:record[i]){
            if(p>=inf) dec(cnt,p-inf);
            else cnt[p]++;
        }
        //cout<<i<<" "<<i+(*rbegin(cnt)).first<<" "<<record[i].size()<<endl;
        ans=std::min(ans,i+(*rbegin(cnt)).first);
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e4;
//constexpr ll MOD=1e5;
constexpr ll MAX=3e6;
constexpr ll inf=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template<typename T>
struct Segment_tree{
    ll N;
    T mem;
    vector<T> node;
    Segment_tree(vector<T> &X,T m):mem(m){
        ll sz=X.size();
        N=1;
        while(N<sz) N*=2;
        node.resize(2*N-1,mem);
        rep(i,0,sz) node[N-1+i]=X[i];
        per(i,N-2,0){
            node[i]=Compare(node[i*2+1],node[i*2+2]);
        }
    }
    T Compare(T &A,T &B){
        return std::min(A,B);
    }
    void update(ll X,T val){
        X+=N-1;
        node[X]=val;
        while(X>0){
            X=(X-1)/2;
            node[X]=Compare(node[X*2+1],node[X*2+2]);
        }
    }
    T Query(ll a,ll b,ll now=0,ll l=0,ll r=-1){ //[a,b),[l,r)
        if(r<0) r=N;
        if(r<=a||b<=l) return mem;
        if(a<=l&&r<=b) return node[now];
        auto vl=Query(a,b,now*2+1,l,(l+r)/2),vr=Query(a,b,now*2+2,(l+r)/2,r);
        return Compare(vl,vr);
    }
    ll lower_bound(ll left,ll right,T val,ll now=0,ll l=0,ll r=-1){
        if(r<0) r=N;
        if(node[now]<val||l>=right||left>=r) return r;
        else if(now>=N-1) return l;
        ll vl=lower_bound(left,right,val,now*2+1,l,(l+r)/2);
        if(vl==(l+r)/2) return lower_bound(left,right,val,now*2+2,(l+r)/2,r);
        return vl;
    }
};
template<typename T>
struct lazy_Segment_tree{
    int N;
    vector<T> node,lazy;
    T INF;
    vector<bool> flag;
    lazy_Segment_tree(vector<T> X,T Y):INF(Y){
        N=1;
        while(X.size()>N) N*=2;
        node.resize(2*N-1,Y);
        lazy.resize(2*N-1);
        flag.resize(2*N-1);
        rep(i,0,X.size()) node[i+N-1]=X[i];
        per(i,N-2,0) node[i]=compare(node[i*2+1],node[i*2+2]);
    }
    T compare(T X,T Y){
        return std::max(X,Y);
    }
    T plus(T X,int l,int r){
        return X;
    }
    void eval(int now,int l,int r){
        if(flag[now]){
            if(r-l>1){
                flag[now*2+1]=flag[now*2+2]=1;
                lazy[now*2+1]=lazy[now*2+2]=lazy[now];
            }
            node[now]=lazy[now];
            flag[now]=0;
        }
    }
    void update(int a,int b,T add,int now=0,int l=0,int r=-1){
        if(r<0) r=N;
        eval(now,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            lazy[now]=add;
            flag[now]=1;
            eval(now,l,r);
        }
        else{
            update(a,b,add,now*2+1,l,(r+l)/2);
            update(a,b,add,now*2+2,(r+l)/2,r);
            node[now]=compare(node[now*2+1],node[now*2+2]);
        }
    }
    T Query(int a,int b,int now=0,int l=0,int r=-1){
        if(r<0) r=N;
        eval(now,l,r);
        if(b<=l||r<=a) return INF;
        if(a<=l&&r<=b) return node[now];
        return compare(Query(a,b,now*2+1,l,(r+l)/2),Query(a,b,now*2+2,(r+l)/2,r));
    }
    ll lower_bound(ll left,ll right,T val,ll now=0,ll l=0,ll r=-1){
        eval(now,l,r);
        if(r<0) r=N;
        if(node[now]<val||l>=right||left>=r) return r;
        else if(now>=N-1) return l;
        ll vl=lower_bound(left,right,val,now*2+1,l,(l+r)/2);
        if(vl==(l+r)/2) return lower_bound(left,right,val,now*2+2,(l+r)/2,r);
        return vl;
    }
};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,ll a){
        x++;
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        x++;
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
    ll lower_bound(ll X){
        if(sum(N)<X) return -1;
        ll ret=0,memo=1,sum=0;
        while(memo*2<=N) memo*=2;
        while(memo>0){
            if(memo+ret<=N&&sum+bit[memo+ret]<X){
                sum+=bit[memo+ret];
                ret+=memo;
            }
            memo/=2;
        }
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        if(siz[Y]<siz[X]) std::swap(X,Y);
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
struct Strongly_Connected_Components{
    ll N,M;
    vii edge,ver;
    vi ind;
    Strongly_Connected_Components(vii e){
        ll n=e.size();
        ll m=0;
        vii revedge(n);
        ind.resize(n);
        rep(i,0,n){
            m+=e[i].size();
            for(auto p:e[i]) revedge[p].pb(i);
        }
        vi num(n,-1),po(n);
        vector<bool> seen(n);
        ll cnt=0;
        rep(i,0,n){
            if(num[i]==-1){
                dfs(i,e,num,cnt);
            }
        }
        rep(i,0,n) po[num[i]]=i;
        per(i,n-1,0){
            ll X=po[i];
            if(!seen[X]){
                std::queue<ll> que;
                vi v;
                que.push(X);
                seen[X]=1;
                while(!que.empty()){
                    ll now=que.front(); que.pop();
                    v.pb(now);
                    ind[now]=ver.size();
                    for(auto p:revedge[now]){
                        if(!seen[p]){
                            seen[p]=1;
                            que.push(p);
                        }
                    }
                }
                ver.pb(v);
            }
        }
        N=ver.size();
        M=0;
        edge.resize(N);
        rep(i,0,n){
            for(auto p:e[i]){
                if(ind[i]==ind[p]) continue;
                M++;
                edge[ind[i]].pb(ind[p]);
            }
        }
    }
    void dfs(ll now,vii &e,vi &num,ll &cnt){
        num[now]=0;
        for(auto next:e[now]){
            if(num[next]==-1){
                dfs(next,e,num,cnt);
            }
        }
        num[now]=cnt++;
    }
};
struct lowlink{
    ll N;
    vii edge;
    vi ord,low,aps;
    vector<bool> used;
    vector<pii> bridges;
    lowlink(vii e):edge(e){
        N=edge.size();
        used.resize(N);
        ord.resize(N);
        low.resize(N);
        ll cnt=0;
        rep(i,0,N){
            if(!used[i]) dfs(i,cnt,-1);
        }
    }
    void dfs(ll now,ll &cnt,ll from){
        used[now]=1;
        ord[now]=cnt++;
        low[now]=ord[now];
        bool flag=0;
        for(auto next:edge[now]){
            if(!used[now]){
                dfs(next,cnt,now);
                low[now]=std::min(low[now],low[next]);
                if(from!=-1&&ord[now]<=low[next]) flag=1;
                if(ord[now]<low[next]) bridges.pb(mp(now,next));
            }
            else if(next!=from) low[now]=std::min(low[now],ord[next]);
        }
        if(from==-1&&edge[now].size()>=2) flag=1;
        if(flag) aps.pb(now);
    }
};
struct Directed_Gragh{
    ll N,M;
    vii edge;
    Directed_Gragh(vii e):edge(e){
        N=edge.size();
        rep(i,0,N) M+=edge[i].size();
    }
    vi sort(){
        vi ret;
        vi cnt(N);
        rep(i,0,N){
            for(auto p:edge[i]) cnt[p]++;
        }
        std::queue<ll> que;
        rep(i,0,N){
            if(cnt[i]==0) que.push(i);
        }
        while(!que.empty()){
            ll now=que.front(); que.pop();
            ret.pb(now);
            for(auto next:edge[now]){
                cnt[next]--;
                if(cnt[next]==0) que.push(next);
            }
        }
        return ret;
    }
};
struct Tree{
    int N;
    vii dp;
    vi par;
    vi dist;
    vi subtree;
    vii edge;
    Tree(vii E):edge(E){
        N=edge.size();
        dp.resize(N);
        par.resize(N);
        dist.resize(N,-1);
        for(int i=0;i<N;i++) dp[i].resize(30);
        dist[0]=dp[0][0]=0;
        std::queue<int> que;
        que.push(0);
        while(!que.empty()){
            int now=que.front(); que.pop();
            for(int i=0;i<edge[now].size();i++){
                int next=edge[now][i];
                if(dist[next]==-1){
                    dist[next]=dist[now]+1;
                    que.push(next);
                    par[next]=now;
                    dp[next][0]=now;
                }
            }
        }
        for(int i=1;i<30;i++){
            for(int j=0;j<N;j++) dp[j][i]=dp[dp[j][i-1]][i-1];
        }
    }
    int LCA(int X,int Y){
        if(dist[X]<dist[Y]) std::swap(X,Y);
        {
            int Z=dist[X]-dist[Y];
            for(int i=0;i<30;i++){
                if(Z&(1<<i)){
                    X=dp[X][i];
                }
            }
        }
        if(X==Y) return X;
        for(int i=29;i>=0;i--){
            if(dp[X][i]!=dp[Y][i]){
                X=dp[X][i];
                Y=dp[Y][i];
            }
        }
        return dp[X][0];
    }
    void Subtree(){
        subtree.resize(N,-1);
        dfs(0);
    }
    void dfs(ll now){
        subtree[now]=1;
        for(auto next:edge[now]){
            if(subtree[next]==-1){
                dfs(next);
                subtree[now]+=subtree[next];
            }
        }
    }
};
template<typename T>
vi Declination_sort(ll N,T x,T y,vi X,vi Y){
    vi ret(N);
    vector<std::pair<long double,ll>> data(N);
    rep(i,0,N){
        long double A=X[i]-x,B=Y[i]-y;
        long double rad=atan2(B,A);
        data[i]=mp(rad,i);
    }
    sort(ALL(data));
    rep(i,0,N) ret[i]=data[i].second;
    return ret;
}
struct Convex_Hull{
    ll N;
    vi X,Y;
    Convex_Hull(vi A,vi B):X(A),Y(B){
        N=X.size();
        ll sx=0,sy=0;
        rep(i,0,N){
            sx+=X[i];
            sy+=Y[i];
        }
        double x=sx*1.0/N,y=sy*1.0/N;
        vi ind=Declination_sort<long double>(N,x,y,X,Y);
        vi C(N),D(N);
        rep(i,0,N){
            C[i]=X[ind[i]];
            D[i]=Y[ind[i]];
        }
        X=C;
        Y=D;
    }
    /*vi Find(){

    }*/
};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vi fac,finv,inv;
void COMinit() {
    fac.resize(MAX);
    finv.resize(MAX);
    inv.resize(MAX);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
void comp(vi &A){
    std::map<ll,ll> memo;
    rep(i,0,A.size()) memo[A[i]]=0;
    ll cnt=0;
    for(auto &p:memo) p.second=cnt++;
    rep(i,0,A.size()) A[i]=memo[A[i]];
}
void dec(std::map<ll,ll> &mem,ll X){
    mem[X]--;
    if(mem[X]==0) mem.erase(X);
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::random_device rnd;
    std::mt19937 mt(rnd());
    ll N,M; cin>>N>>M;
    vi A(N),B(N);
    rep(i,0,N) cin>>A[i]>>B[i];
    vector<pii> data(M);
    rep(i,0,M) cin>>data[i].first>>data[i].second;
    sort(ALL(data));
    {
        std::map<ll,ll> a;
        rep(i,0,M) a[data[i].first]=data[i].second;
        data.clear();
        for(auto p:a) data.pb(p);
        M=a.size();
    }
    std::map<ll,ll> cnt;
    vi mem(M);
    rep(i,0,M) cnt[data[i].second]++;
    rep(i,0,M){
        mem[i]=(*cnt.rbegin()).first+1;
        dec(cnt,data[i].second);
    }
    ll ans=inf;
    const ll max=1e6+10;
    vector<vector<pii>> record(max+1);
    rep(i,0,N){
        ll min=inf;
        rep(j,0,M){
            if(data[j].first>=A[i]){
                ll X=data[j].first-A[i];
                ll Y=0;
                if(j) Y=std::max(0ll,data[j-1].first+1-A[i]);
                ll Z=std::max(0ll,mem[j]-B[i]);
                record[Y].pb(mp(Z,X));
            }
        }
    }
    cnt.clear();
    std::priority_queue<pii> que;
    rep(i,0,max){
        ll max=0;
        for(auto p:record[i]){
            if(m[p.])
            que.push(p);
        }
        while(!que.empty()){
            auto p=que.top();
            if(p.second>=i){
                max=p.first; break;
            }
            que.pop();
        }
        //cout<<i<<" "<<i+(*rbegin(cnt)).first<<" "<<record[i].size()<<endl;
        ans=std::min(ans,i+max);
    }
    cout<<ans<<endl;
}