n, m = map(int, input().split())
s = []
c = []
for _ in range(m):
    ss, cc = map(int, input().split())
    s.append(ss)
    c.append(cc)

ans = [[] for _ in range(n)]

for i, j in zip(s, c):
    if not j in ans[i-1]:
        ans[i-1].append(j)
answer = ''
for i in range(n):
    if len(ans[i]) == 0:
        tmp = 0
    else:
        tmp = min(ans[i])
    answer += str(tmp)

if answer[0] == '0':
    answer = -1
else:
    answer = int(answer)

for i in range(n):
    if len(ans[i]) >= 2:
        print(-1)
        exit()

print(answer)
