import sys
input = sys.stdin.readline

def swap_str(s_org, s1, s2, temp='*q@w-e~r^'):
    return s_org.replace(s1, temp).replace(s2, s1).replace(temp, s2)

def main():
    N, M = map(int, input().split())
    ans = '123'
    used_s = []
    used_c = []

    for _ in range(M):
        s, c = input().split()
        if s in used_s and c not in used_c:
            print('-1')
            sys.exit() 
        else:
            ans = swap_str(ans, ans[int(s)-1], c)
            used_s.append(s)
            used_c.append(c)
    if ans.find('0') == 0:
        print('-1')
    else:
        print(ans)

main()