n, m = map(int, input().split())
num = ['x'] * n
flag = 0

if n == 1:
    for i in range(m):
        if m == 0:
            print(0)
            flag = 1
            break
        else:
            s, c = map(int, input().split())
            if num[s-1] == 'x':
                num[s-1] = c
            else:
                if num[s-1] != c:
                    print(-1)
                    flag = 1
                    break
    if flag == 0:
        print(num[s-1])

else:
    for i in range(m):
        s, c = map(int, input().split())
        if num[s-1] == 'x':
            num[s-1] = c
            if s == 1 and c == 0:
                print(-1)
                flag = 1
                break
                
        else:
            if num[s-1] != c:
                print(-1)
                flag = 1
                break
    if flag == 0:
        if num[0] == 'x':
            num[0] = 1
        for j in range(1, n):
            if num[j] == 'x':
                num[j] = 0 
        str_num = map(str, num)
        print(''.join(str_num))