N, M = map(int,input().split())
v = set()
s,c = [0]*M, [0]*M
for i in range(M):
    x, y = map(int, input().split())
    s[i], c[i] = x-1, y
    x -= 1
    v.add((x,str(y)))

ans = list(['0']*N)
for i in s:
    L = [(x,y) for x,y in v if x==i]
    if len(L)>1:
        print(-1)
        exit()

for i,j in v:
    ans[i] = j

if ans[0]=='0':
    print(-1)
else:
    num = ''.join(ans)
    print(num)