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

import sys
num = ['9' for _ in range(N)]
#%%
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1  and c == 0:
        print(-1)
        sys.exit()
    # indexをゼロ始まり
    s -= 1
    if num[s] != '9':
        if num[s] != c:
            print(-1)
            sys.exit()
    else:
        num[s] = c
#%%
if num[0] == '9':
    num[0] = 1

for i in range(N):
    if num[i] == '9':
        num[i] = 0

ans = int(''.join(map(str, num)))
print(ans)

