# AtCoder
from collections import defaultdict
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
ans = [0]*N

d = defaultdict(list)
for i in range(M):
    s = sc[i][0]
    c = sc[i][1]

    d[s].append(c)

for k, v in d.items():
    if list(set(v)) == v and len(v) >= 2:
        print(-1)
        exit()
    else:
        ans[k-1] = v[-1]

print(''.join(map(str, ans)))
