import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    scs = [list(map(int, input().split())) for i in range(m)]

    if n == m and n == 1 and scs[0][0] == 1 and scs[0][1] == 0:
        print(0)
        return

    digits = [None] * n

    for i in range(m):
        

        if scs[i][0] == 1 and scs[i][1] == 0 and n != 1:
            print('-1')
            return
        try:
            a = digits[scs[i][0]-1]
        except:
            print('-1')
            return     
        if digits[scs[i][0]-1] is None:
            digits[scs[i][0]-1] = scs[i][1]
        else:
            if digits[scs[i][0]-1] == scs[i][1]:
                continue
            else:
                print('-1')
                return
    
    for i in range(n):
        if i == 0 and digits[i] is None:
            digits[i] = 1
            continue
        if digits[i] is None:
            digits[i] = 0
    
    ans = str()

    for i in range(n):
        ans += str(digits[i])
    print(ans)
    return

if __name__ == '__main__':
    main()
