#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
    int n,m;
    cin>>n>>m;
    vector<string>vec(n);
    int s;
    string c;
    rep(i,m){
       cin>>s>>c;
       if(n!=1&&s==1&&c=="0"){
            cout<<-1<<endl;
             return 0;
        }
        if(vec.at(s-1)==""){
           vec.at(s-1)=c;
        }else if(vec.at(s-1)!=c){
           cout<<-1<<endl;
           return 0;
         }
      
   }
   string ans="";

   if(n!=1&&vec.at(0)==""){
       vec.at(0)="1";
   }
   rep(i,n){
       if(vec.at(i)==""){
           ans+="0";
       }else{
           ans+=vec.at(i);
       }
   }
   cout<<ans<<endl;

    
}


#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= (_T)base;
	}
	return ans;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	int N, M;
	get(N, M);

	std::vector<int> num(N, -1);

	for (int i = 0; i < M; i++) {
		int s, c;
		get(s, c);

		if ((s > N) || ((num[s - 1] != -1) && (num[s - 1] != c))) {
			printf("-1\n");
			return;
		}
		num[s - 1] = c;
	}

	if (num[0] == 0 && N > 1) {
		printf("-1\n");
		return;
	}
	else if (num[0] == -1 && N > 1) num[0] = 1;

	for (int i = 0; i < N; i++) {
		if (num[i] < 0) num[i] = 0;
		printf("%d", num[i]);
	}
	putchar('\n');
}

