N, M = map(int, input().split())
lst = [0, 0, 0]
k = 1

for i in range(M):
    s, c = map(int, input().split())
    if lst[s-1] != c and lst[s-1] != 0:
        k = 0

    else:
        lst[s-1] = c

ans = lst[:N]

if k or (N == 1 and ans[0] == 0):
    print(''.join(map(str,ans)))

else:
    print(-1)