n, m = map(int, input().split())
ans = [0] * n
cklist = [0] * n
result = True
for x in range(m):
    s, c = map(int, input().split())
    if n != 1 and s == 1 and c == 0: 
        print(-1)
        result = False
        break
    elif cklist[s - 1] == 1 and ans[s - 1] != c:
        print(-1)
        result = False
        break
    else:
        ans[s - 1] = c
        cklist[s - 1] = 1
if(ans[0] == 0): ans[0] += 1
ans_str = [str(n) for n in ans]
if(result == True): print(''.join(ans_str))