n, m = map(int, input().split())
s_m, c_m = [], []
for i in range(m):
    s_m.append(0)
    c_m.append(0)
    s_m[i], c_m[i] = map(int, input().split())

def test():
    result = [0]*n
    for i in range(m):
        if s_m[i] == 1 and c_m[i] == 0:
            print(-1)
            return 0          
        for j in range(i+1, m):
            if s_m[i] == s_m[j] and c_m[i] != c_m[j]:
                print(-1)
                return 0
        result[s_m[i]-1] = c_m[i]
    if result[0] == 0:
        result[0] = 1
    for ans in result:
        print(ans, end='')
    print()
    return 0
test()