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
    else:
        num[s-1] = c

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

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

if num[0] == -1:
    num[0] = 1

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


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