n,m = map(int,input().split())
sc = []
for _ in range(m):
    sc.append(list(map(int,input().split())))
ans = -1
flag = False
if n == 1:
    tmp = sc[0][1]
    for x in sc:
        s = x[0]
        c = x[1]
        if tmp != c:
            break
        ans = tmp
elif n == 2:
    tmp = [-1,-1]
    for x in sc:
        s = x[0]
        c = x[1]
        if tmp[s-1] != c and tmp[s-1] != -1:
            flag = True
            break
        if s == 1 and c == 0:
            flag = True
            break
        tmp[s-1] = c
    if tmp[0]==-1:
        tmp[0] = 1
    if tmp[1]==-1:
        tmp[1] = 0
    if not flag:
        ans = tmp[0]*10+tmp[1]
else:
    tmp = [-1,-1,-1]
    for x in sc:
        s = x[0]
        c = x[1]
        if tmp[s-1] != c and tmp[s-1] != -1:
            flag = True
            break
        if s == 1 and c == 0:
            flag = True
            break
        tmp[s-1] = c
    if tmp[0]==-1:
        tmp[0] = 1
    if tmp[1]==-1:
        tmp[1] = 0
    if tmp[2]==-1:
        tmp[2] = 0
    if not flag:
        ans = tmp[0]*100+tmp[1]*10+tmp[2]
print(ans)