#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, m = list(map(int,ipti().split()))
    s = [0] * m
    c = [0] * m
    ans = [-1] * n

    for i in range(m):
        s[i], c[i] = list(map(int,ipti().split()))
        s[i] -= 1
        if ans[s[i]] == -1:
            ans[s[i]] = c[i]
        elif ans[s[i]] == c[i]:
            pass
        else:
            print(-1)
            sys.exit()

    if ans[0] == -1:
        ans[0] = 1
    if ans[0] == 0:
        print(-1)
        sys.exit()

    for i in range(1,n):
        if ans[i] == -1:
            ans[i] = 0

    for i in range(n):
        ans[i] = str(ans[i])

    print(''.join(ans))

if __name__ == '__main__':
    main()