import numpy as np

N, M = map(int, input().split())

l = [list(map(int, input().split())) for i in range(M)]

r = np.zeros(3)
r -= 1

f = True
for i, j in l:
    i -= 1
    if i == 0 and j == 0:
        f = False
    if N == 2 and i == 1 and j == 0:
        f = False
    if r[i] == -1:
        r[i] = j
    if r[i] != -1 and r[i] != j:
        f = False
if f:
    l = [str(int(max(i, 0))) for i in r]
    s = ''.join(l)
    if N == 3:
	    print(s)
    if N == 2:
      	print(s[1:])
    if N == 1:
        print(s[2:])
else:
    print(-1)