n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
temp = [-1] * n
ans = -1

for i in sc:
    if temp[i[0]-1] != -1 and temp[i[0]-1] != i[1]:
        print(-1)
        exit()
    temp[i[0]-1] = i[1]

if n == 1:
    mini = 0
    maxi = 10
if n == 2:
    mini = 10
    maxi = 100
if n == 3:
    mini = 100
    maxi = 1000

print(mini,maxi)
for i in range(mini,maxi):
    s = str(i)
    ok = True
    for j in sc:
        if s[j[0]-1] != str(j[1]):
            ok = False
    if ok:
        ans = i
        print(ans)
        exit()

print(ans)