N, M = list(map(int, input().split()))
s_c = [list(map(int, input().split())) for _ in range(M)]
s = []
c = []
for i, j in s_c:
    s.append(i)
    c.append(j)

num = [None for _ in range(N)]
for i in range(M):
    if(num[s[i] - 1] is None):
        if(s[i] == 1 and c[i] == 0):
            print(-1)
            sys.exit()
        num[s[i] - 1] = c[i]
    else:
        if(num[s[i] - 1] != c[i]):
            print(-1)
            sys.exit()

num = [0 if n is None else n for n in num]
if(num[0] == 0):
    num[0] = 1

for n in num:
    print(n, end="")
print()