N, M = map(int,input().split())
x = [0]*M
for i in range(M):
    x[i] = input()
y = list(set(x))
s = [0]*len(y)
c = [0]*len(y)
for i in range(len(y)):
    s[i],c[i] = map(int, y[i].split())
cnt = [0]*N
ans = [0]*N
for i in range(len(y)):
    cnt[s[i]-1] += 1
    ans[s[i]-1] = c[i]

error = 0
if max(cnt) >= 2:
    error += 1
if (N >= 2 and ans[0] == 0):
    error += 1
if error >= 1:
    print("-1")
else:
    print("".join(map(str, ans)))