import sys
n,m = list(map(int,input().split()))

a = [list(map(int,input().split())) for i in range(m)]

ans = '0' * n
temp = []

for i in range(m):
    if a[i][0] - 1 not in temp or str(a[i][1]) == ans[a[i][0]-1]:
        ans = ans[:a[i][0]-1] + str(a[i][1]) + ans[a[i][0]:]
    else:
        print(-1)
        sys.exit()

if ans[0] == '0':
    print(-1)
else:
    print(ans)
