n,m = map(int,input().split())
digit = [[] for _ in range(n+1)]
for _ in range(m):
    s,c = map(int,input().split())
    digit[s].append(c)
ret = ''
for d in digit[1:]:
    if len(set(d))>=2:
        print(-1)
        exit()
    elif len(set(d))==1:
        ret += str(d[0])
    else:
        ret += '0'
if n>1:
    print(ret if ret[0]!='0' else -1)
else:
    print(ret)