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

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

    else:
        k = 0
        break

for i in range(3):
    if lst[i] == -1:
        lst[i] = 0

ans = lst[:N]

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

else:
    print(-1)