import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    n,m = map(int,input().split())
    s = [0] * m
    c = [0] * m
    for i in range(m):
        s[i],c[i] = map(int,input().split())
    num = [0 for i in range(n)]
    for i in range(m):
        if s[i] == 1 and not c[i]:
            print(-1)
            return
        if not num[s[i]-1]:
            num[s[i]-1] = c[i]
        elif num[s[i]-1] == c[i]:
            continue
        else:
            print(-1)
            return
    if not num[0]:
        num[0] = 1
    ans = [str(x) for x in num]
    print(''.join(ans))
    return

if __name__=='__main__':
    main()
