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


def solv(N, M, SC):
    ans = [" "] * N
    for s, c in SC:
        if ans[s-1] == " ":
            ans[s-1] = c
        elif ans[s-1] != c:
            return -1
    if ans[0] == " ":
        ans[0] = "1"
    elif ans[0] == "0":
        return -1
    ans = "".join(ans)
    ans = ans.replace(" ", "0")
    return int(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), c))

    ans = solv(N, M, SC)

    print(ans)
