N, M = map(int,input().split())

d =dict([ (i,set()) for i in range(1, N+1)])

for i in range(M):
    s,c = map(int,input().split())
    d[s].add(c)

flag = 1


if ((0 in d[1]) or (len(d[1]) > 1)) :
    if 0 in d[1] and N == 1:
        flag = 1
        ans = "0"
    else:
        flag = 0
else:
    ans = str(list(d[1])[0]) if len(d[1]) else "1"
    for i in range(2, N+1):
        if len(d[i]) > 1:
            flag = 0
            break
        elif len(d[i]) == 0:
            ans += "0"
        else:
            ans += str(next(iter(d[i])))

if flag:
    print(ans)
else:
    print(-1)
