# C
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    ss, cc = map(int, input().split())
    s.append(ss)
    c.append(cc)
    
bool = True
ans = [-1]*n
for i in range(m):
    if ans[s[i]-1] == -1 or ans[s[i]-1] == c[i]:
        ans[s[i]-1] = c[i]
    else:
        bool = False
        break
        
if ans[0] == 0 or ans[0] == -1:
    bool = False
    
for i in range(n):
    if ans[i] == -1:
        ans[i] = 0
        
if bool == False:
    print(-1)
else:
    for v in ans:
        print(v, end='')