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

num = [0] * N
cnt = 0
for i in range(M):
    s, c = map(int, input().split())
    if cnt != 0:
        if num[s - 1] != c:
            print(-1)
            sys.exit()
    if num[s - 1] != 0:
        if num[s - 1] != c:
            print(-1)
            sys.exit()

    num[s-1] = c
    cnt += 1

if N >= 2:
    if num[0] == 0:
        print('-1')
        sys.exit()

for i in num:
    print(i, end='')