n, m = map(int, input().split())
num = [0]*n
ans = 0

for i in range(m):
    s, c = map(int, input().split())
    if i == 0 or num[s-1] > c:
        num[s-1] = c
for i in range(n):
    ans += num[i]*10**(n-(i+1))

if len(str(ans)) == n:
    print(ans)
else:
    print(-1)