from sys import stdin
import sys
import math

N, M = list(map(int, stdin.readline().rstrip().split()))
S = []
h = {}
for i in range(M):
    s, c = list(map(int, stdin.readline().rstrip().split()))
    S.append([s, c])
    if h.get(s, -1) == -1:
        h[s] = c
    elif h.get(s, -1) != c:
        print(-1)
        sys.exit()

ans = 0
digit = 0
for j in range(1, N+1)[::-1]:
    n = h.get(j, 0)
    ans += n * 10**digit
    digit += 1

if n == 0:
    print(-1)
    sys.exit()


#print(S)
print(ans)

