import re
from sys import stdin


def get_result(data):
    N, M = data[0]
    if M == 0:
        if N == 1:
            return '0'
        elif N == 2:
            return '10'
        elif N == 3:
            return '100'

    tmp = [-1 for _ in range(N)]
    for i in range(M):
        s, c = data[i+1]
        if tmp[s-1] == -1:
            tmp[s-1] = c
        elif tmp[s-1] != -1 and tmp[s-1] != c:
            return -1
    
    ans = ''.join([str(val) for val in tmp])
    ans = ans.replace('-1', '0')
    if ans == '0': return '0'
    return '-1' if re.search(r'^(0[0-9]*)$', ans) else ans

if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)
