N, M = map(int, input().rstrip().split(' '))
temp = [0] * N

flag = 0
for i in range(M):
    s, c = map(int, input().rstrip().split(' '))
    if temp[s - 1] != 0 and temp[s-1] != c:
        flag = 1
        break
    else:
        temp[s - 1] = c

if (temp[0] == 0 and N >= 2) or flag == 1:
    print(-1)
else:
    ans = ''
    for n in temp:
        ans += str(n)

    print(ans)

