#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-07-11 16:16:44 +0900
# LastModified: 2020-07-11 16:25:33 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, m = map(int, input().split())
    number = [-1]*(n+1)
    for _ in range(m):
        s, c = map(int, input().split())
        if number[s]!=-1 and c != number[s]:
            print(-1)
            return
        if s==1 and c==0:
            print(-1)
            return
        number[s] = c
    number = [number[i] if number[i]!=-1 else 0 for i in range(1, n+1)]
    for a in number:
        print(a, end="")
    print()



if __name__ == "__main__":
    main()
