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]:]
        temp.append(a[i][0] - 1)
        if (a[i][0] - 1) == 0 and a[i][1] == 0 and n != 1:
            print(-1)
            sys.exit()
    else:
        print(-1)
        sys.exit()

if n == 1 and int(ans) == 0:
    print(0)
    sys.exit()

if int(ans) == 0:
    print(-1)
    sys.exit()
    
if ans[0] == '0':
    ans = '1' + ans[1:]
    print(ans)
else:
    print(ans)
