n, m = list(map(int, input().split()))

    
out = [0]*n
err_flg = False

for i in range(m):
    s = list(map(int, input().split()))

    if out[s[0]-1]==0:
        out[s[0]-1] = s[1]
    elif out[s[0]-1]!=s[1]:
        err_flg = True
    else:
        out[s[0]-1] = s[1]



if out[0]==0:
    err_flg = True
out_s = "".join(map(str,out))

if m==0 and n==1:
    print(0)
elif err_flg:
    print('-1')
else:
    print(out_s)