import numpy as np
import math

n, m = list(map(int, input().split(" ")))
mapp = np.zeros((n, n)) - 1
mapp[0, 0] = 0

p = []
for i in range(n + 1):
temp = m - i ** 2
if temp < 0:
continue
t = math.sqrt(temp)
if t - int(t) <= 1e-7:
p.append((int(i), round(t)))
temp = []
for a, b in p:
temp.append((-a, -b))
temp.append((a, -b))
temp.append((-a, b))
directions = list(set(temp + p))


def is_inside(pp, qq):
return 0 <= pp <= n - 1 and 0 <= qq <= n - 1


que = [(0, 0)]