# abc157 c
def ans():
    n, m = [int(i) for i in input().split()]
    digit_dict = {}
    for _ in range(m):
        s, c = [int(i) for i in input().split()]
        if s not in digit_dict:
            digit_dict[s] = c
            continue
        elif digit_dict[s] != c:
            print('-1')
            return
    for i in range(0, 10**n):
        stri = str(i)
        ans = True
        if len(stri) == n:
            for j, k in digit_dict.items():
                if istr[j-1] != k:
                    ans = False
            if ans:
                print(i)
                return
        print('-1')
        return
if __name__ == '__main__':
    ans()