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

num = [-1]*n
#print(num)
for i in range(m):
    if (num[sc[i][0]-1] == -1) or (num[sc[i][0]-1] == sc[i][1]):
        num[sc[i][0]-1] = sc[i][1]
    else:
        print(-1)
        exit()

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

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

for i in range(n):
        ans += num[i]*10**(n-i-1)
print(ans)