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

num = [-1]*N
flag = False
for _ in range(M):
    s, c = map(int, input().split())

    if num[s-1] != -1 and num[s-1] != c:
        flag = True
    
    num[s-1] = c

for i in range(M):
    if num[i] == -1:
        num[i] = 0

if flag:
    print('-1')
    exit(0)

if num[0] == 0:
    print('-1')
    exit(0)

num = list(map(str, num))
print(''.join(num))