N, M = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(M)]
c = []

for i in range(N):
    c.append(0)

flg = True
for i in s:
    if c[i[0] - 1] == 0:
        c[i[0] - 1] = i[1]
    else:
        flg = False
        break

if flg == True:
    c = map(str, c)
    d = ''.join(c)

    if d[:1] == '0':
        print("-1")
    else:
        print(d)
else:
    print("-1")