n,m =  map(int,input().split())
s = []
for i in range(m):
    s.append(list(input().split()))
ans_dict = {}
for i in range(m):
    if s[i][0] in ans_dict and s[i][1] in ans_dict.values():
        ans_dict[s[i][0]] = s[i][1]
    elif s[i][0] in ans_dict and s[i][1] not in ans_dict.values():
        print("-1")
        break
    elif s[i][0] not in ans_dict:
        ans_dict[s[i][0]] = s[i][1]
ans = ""
for i in reversed(range(n)):
    if str(i+1) in ans_dict:
        ans+=ans_dict[str(i+1)]
    else:
        ans+="0"
print(ans[::-1])