N,M = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(M)]
L = sorted(l)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
for n in range(M-1):
    if (L[n][0] == L[n+1][0]) and (L[n][1] != L[n+1][1]):
        ans = -1
        break
    else:
        s = get_unique_list(L)
        m = len(s)
        if s[0][0] != 1:
            ans = 10**(M-1)
        else:
            ans = 0
        for n in range(m):
            ans += s[n][1]*(10**(M-s[n][0]))
print(ans)