N,M = map(int, input().split())
s = []
c = []
t_1 = []
t_2 = []
for i in range(M):
    t_1,t_2 = map(int, input().split())
    s.append(t_1)
    c.append(t_2)

tmp = 0
for k in range(M):
    if k+1 != M:
        if s[k] > s[k+1]:
            tmp = s[k]
            s[k] = s[k+1]
            s[k+1] = tmp
            tmp = c[k]
            c[k] = c[k+1]
            c[k+1] = tmp
tmp = 0
ans = []
for j in range(M):
    if s[j-1] != s[j]:
        ans.append(c[j])
    elif j == 0:
            ans.append(c[j])
    else :
        if c[j-1] == c[j]:
            ans.append(0)
        else :
            tmp = 1
if len(ans) == N:
    if tmp != 1:
        print(''.join(map(str,ans)))
    else :
        print(-1)
else :
    print(-1)