#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m = map(int, input().split())
List = [list(map(int, input().split())) for _ in range(m)]

for i in range(10**n):
    flag = 1
    num = str(i)
    for j in range(m):
        if n >= 2 and List[j][0] == 1 and List[j][1] == 0:
            flag = 0
            i = 999
            break;

        elif len(num) >= List[j][0]:
            if str(List[j][1]) != num[List[j][0]-1] :
                flag = 0

        else:
            flag = 0


    if flag == 1:
        if n >= 2 and num[0] != "0":
            break;

if i == 999 and flag == 0:
    print(-1)
else:
    print(i)
