import sys
n, m, *s_c = map(int, open(0).read().split())

num = [0]*n
for i in range(m):
    if num[s_c[2*i] - 1] == 0:
        num[s_c[2*i] - 1] = s_c[2*i+1]
    elif num[s_c[2*i] - 1] == s_c[2*i+1]:
        continue
    else:
        print(-1)
        sys.exit()
        
if num[0] == 0:
    print(-1)
    sys.exit()
    
flag_num = int(''.join(map(str, num)))
print(flag_num)