N, M = list(map(int, input().split()))
s, c = [0] * M, [0] * M
num = [0] * N
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))
ss = set(s)
for i in range(1, N + 1):
    if i in ss:
        num[i - 1] = 9
    else:
        num[i - 1] = 0
for i, v in enumerate(s):
    if num[v - 1] > c[i]:
        num[v - 1] = c[i]

num = map(str, num)
ni = "".join(num)
ni = int(ni)
if len(str(ni)) != N:
    print(-1)
else:
    print(ni)
