n, m = map(int, input().split())
s = []
c = []
a, b = 0, 0
for i in range(m):
    a, b =  map(int, input().split())
    s.append(a)
    c.append(b)

def isException(n, m, s, c):
    # -1処理
    for i in range(m):
        for j in range(m):
            if i != j and s[i] == s[j] and c[i] != c[j]:
                return True
        if n >= 2 and s[i] == 1 and c[i] == 0:
                return True

if isException(n, m, s, c):
    print('-1')
else:
    cnt = [0]*n
    ans = 0
    for i in range(m):
        cnt[s[i]-1] = c[i]
    for i in range(n):
        ans += cnt[i]*10**(n-(i+1))
    print(ans)