# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007

def main():

    N, M = map(int, input().split())

    keta = [-1] * N

    flag = True
    for _ in range(M):
        s, c = map(int, input().split())
        s = s - 1

        if s == 0 and c == 0:
            flag = False

        if keta[s] == -1:
            keta[s] = c
        else:
            if not keta[s] == c:
                flag = False

    if keta[0] == -1:
        keta[0] = 1

    for i in range(1, M):
        if keta[i] == -1:
            keta[i] = 0

    if flag:
        print(int(''.join(map(str, keta))))
    else:
        print("-1")


if __name__ == '__main__':
    main()
