#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, M, SC):
    A = [-1] * N
    for s, c in SC:
        if A[s-1] == -1:
            A[s-1] = c
        elif A[s-1] != c:
            return -1
    if A[0] == 0:
        if N == 1:
            return 0
        else:
            return -1
    if A[0] == -1:
        A[0] == 1
    for i in range(1, N):
        if A[i] == -1:
            A[i] = 0
    # print(A)
    ans = 0
    for a in A:
        ans *= 10
        ans += a
    return ans


if __name__ == "__main__":

    # N M
    # s_1 c_1
    # \vdots
    # s_M c_M
    #
    N, M = map(int, input().split())
    SC = []
    for _ in range(M):
        s, c = input().split()
        SC.append((int(s), int(c)))

    ans = solv(N, M, SC)

    print(ans)
