N, M = map(int, input().split())
s = []
c = []
num = [0] * N

def judge():
    for i in range(M):
        s1, c1 = map(int, input().split())
        s.append(s1)
        c.append(c1)

    for i in range(M):
        for j in range(M):
            if s[i] == s[j] and i != j and c[i] != c[j]:
                print(-1)
                return

    if N == 3:        
        for i in range(M):
            if s[i] - 1 < 0 or s[i] - 1 > 2:
                print(-1)
                return
            num[s[i] - 1] = c[i]
    elif N == 2:
        for i in range(M):
            if s[i] < 0 or s[i] > 2:
                print(-1)
                return
            num[s[i] - 1 + 1] = c[i]
    else:
        if s[i] + 1 < 0 or s[i] + 1 > 2:
                print(-1)
                return
        num[s[i] - 1 + 2] = c[i] 



    if num[0] == 0:
        if num[1] == 0:
            if num[2] == 0:
                print(-1)
                return
            print(num[2])
        print("{0}{1}".format(num[1], num[2]))
        return
    else:
        print("{0}{1}{2}".format(num[0], num[1], num[2]))
        return

judge()
