def swapStr(S, i, new):
    return S[:i] + str(new) + S[i+1:]

n, m = map(int, input().split())

flag_false = 0
ans = 'n'*n
for i in range(m):
    s, c = map(int, input().split())
    s = s-1
    if ans[s] == 'n':
        ans = swapStr(ans, s, c)
    elif ans[s] != str(c):
        flag_false = 1
        break

if ans[0] == 'n':
    ans = swapStr(ans, 0, 1)
for i in range(1, len(ans)):
    if ans[i] == 'n':
        ans = swapStr(ans, i, 0)

if int(ans)//10**(n-1) == 0:
    flag_false = 1
if flag_false:
    print(-1)
else:
    print(int(ans))