N, M = map(int, input().split())
s = [-1]
c = [-1]
OK = True
x = 0
for i in range(M):
    s_, c_ = map(int, input().split())
    if s_ == 1 and c_ == 0:
        OK = False
    ok = True
    for i in range(len(s)):
        if s[i] == s_:
            ok = False
            if c[i] != c_:
                OK = False
                break
            break
    if ok:
        s.append(s_)
        c.append(c_)
        x += (10 ** (N - s_)) * c_

if x < 10 ** (N - 1):
    x += 10 ** (N - 1)

if OK:
    print(x)
else:
    print(-1)
