import math

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

found = False

for i in range(pow(10,N-1), pow(10,N)):
   
    i_str = str(i)

    passed = True
    for j in range(M):
        if not i_str[s[j]-1] == c[j]:
            passed = False
            break
    if passed:
        found = True
        print(i)
        break

if not found:
    print("-1")