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

Num = [0] * N
Num_ = 0
for i in range(M):
    if s[i] == 1 and c[i] == 0:
        Num_ = -1
        break
    for j in range(M):
        if s[i] == s[j]:
            if c[i] != c[j]:
                Num_ = -1
            break
    Num[s[i]-1] = c[i]
    if Num_[0] == 0:
        Num_[0] = 1
    
if Num_ == 0:
    print(int("".join(map(str, Num))))
else:
    print(Num_)