N, M = map(int, input().split(" "))

ans = 0
sici = []
check = [[] for i in range(3)]
for i in range(M):
    si, ci = map(int, input().split(" "))
    sici.append([si, ci])
    if not ci in check[si-1]:
        check[si-1].append(ci)
        if len(check[si-1]) > 1:
            ans = -1
            break
for si, ci in sici:
    if si > N:
        ans = -1
        break
    # if ci == 0 and si == 1 and N > 1:
    #     ans = -1
    #     break
    if si == 1:
        if N == 1:
            if ans == 0:
                ans += ci
            elif ans == ci:
                continue
            else:
                ans = -1
                break

        if N == 2:
            if ans//10 == 0:
                ans += ci * 10
            elif ans//10 == ci:
                continue
            else:
                ans = -1
                break
        
        if N == 3:
            if ans//100 == 0:
                ans += ci * 100
            elif ans//100 == ci:
                continue
            else:
                ans = -1
                break
    elif si == 2:
        if N == 2:
            if ans%10 == 0:
                ans += ci
            elif ans%10 == ci:
                continue
            else:
                ans = -1
                break
        if N == 3:
            if (ans%100)//10 == 0:
                ans += ci * 10
            elif (ans%100)//10 == ci:
                continue
            else:
                ans = -1
                break
    elif si == 3 and N == 3:
        if ans%10 == 0:
            ans += ci
        elif ans%10 == ci:
            continue
        else:
            ans = -1
            break

if ans < 100 and N == 3:
    ans = -1
if ans < 10 and N == 2:
    ans = -1
print(ans)