#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 n == 1:

        if ans[0] == -1:

            ans[0] = 0

        print((ans[0]))

        sys.exit()

    elif ans[0] == 0:

        print((-1))

        sys.exit()



    if ans[0] == -1:

        ans[0] = 1



    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()

import sys



readline = sys.stdin.readline

MOD = 10 ** 9 + 7

INF = float('INF')

sys.setrecursionlimit(10 ** 5)





def main():

    n, m = list(map(int, readline().split()))

    restriction = [list(map(int, readline().split())) for _ in range(m)]



    # n桁の数字の下限と上限 [begin,end)

    begin = (None, 0, 10, 100)

    end = (None, 10, 100, 1000)



    for num in range(begin[n], end[n]):

        flag = True

        numstr = str(num)

        for i in range(m):

            s_idx = restriction[i][0] - 1  # 左から数えた桁数を-1してインデックスにする

            c_str = str(restriction[i][1])  # 数字

            if numstr[s_idx] != c_str:

                flag = False

        if flag:

            print(num)

            sys.exit()



    print((-1))





if __name__ == '__main__':

    main()

# 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 n == 1:
        if ans[0] == -1:
            ans[0] = 0
        print((ans[0]))
        sys.exit()
    elif ans[0] == 0:
        print((-1))
        sys.exit()
    if ans[0] == -1:
        ans[0] = 1
    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()

import sys

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


def main():
    n, m = list(map(int, readline().split()))
    restriction = [list(map(int, readline().split())) for _ in range(m)]
    # n桁の数字の下限と上限 [begin,end)
    begin = (None, 0, 10, 100)
    end = (None, 10, 100, 1000)
    for num in range(begin[n], end[n]):
        flag = True
        numstr = str(num)
        for i in range(m):
            s_idx = restriction[i][0] - 1  # 左から数えた桁数を-1してインデックスにする
            c_str = str(restriction[i][1])  # 数字
            if numstr[s_idx] != c_str:
                flag = False
        if flag:
            print(num)
            sys.exit()
    print((-1))


if __name__ == "__main__":
    main()

-# import math -# import bisect -# import numpy as np -# import itertools -# import copy -ipti = sys.stdin.readline +readline = sys.stdin.readline -    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)) +    n, m = list(map(int, readline().split())) +    restriction = [list(map(int, readline().split())) for _ in range(m)] +    # n桁の数字の下限と上限 [begin,end) +    begin = (None, 0, 10, 100) +    end = (None, 10, 100, 1000) +    for num in range(begin[n], end[n]): +        flag = True +        numstr = str(num) +        for i in range(m): +            s_idx = restriction[i][0] - 1  # 左から数えた桁数を-1してインデックスにする +            c_str = str(restriction[i][1])  # 数字 +            if numstr[s_idx] != c_str: +                flag = False +        if flag: +            print(num) -    if n == 1: -        if ans[0] == -1: -            ans[0] = 0 -        print((ans[0])) -        sys.exit() -    elif ans[0] == 0: -        print((-1)) -        sys.exit() -    if ans[0] == -1: -        ans[0] = 1 -    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))) +    print((-1))