import sys
import numpy as np
n,m = map(int, input().split())
s = list()
c = list()
for i in range(m):
    a,b = map(int, input().split())
    if not a in s:
        s.append(a)
        c.append(b)
    elif c[s.index(a)] != b:
        print('-1')
        sys.exit()
if c[np.argmin(s)] == 0:
    print('-1')
    sys.exit()
result = 0
for i,v in zip(s,c):
    result += (10**(n - i))*v
print(str(result))