n,m = map(int, input().split())
ans = [-1] *n
f= 0
for i in range(m):
    s,c = map(int, input().split())
    #if (ans[s-1] != -1) and (ans[s-1] != c):  # 重複
    if (ans[s-1] == -1) or (ans[s-1] == c):
        ans[s-1] = c
    else:
        f = 1
if f == 1:
    print('-1')
    exit()

if ans[0] == 0 and len(ans) != 1:  # 1桁以外の頭0
    print('-1')
    exit()

if ans[0] == -1:
    if len(ans) != 1:  # 頭に指定がない時は1
        ans[0] == 1
    else:
        print(0)
        exit()

for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
print(''.join(map(str, ans)))

