#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int n,m;
	cin>>n>>m;
	map<int,int>used;
	vector<int>num(n,0);
	num[0]=1;
	bool ok=true;
	rep(i,m){
		int s,c;
		cin>>s>>c;
		s--;
		if(!used[s]){
			used[s]=1;
			num[s]=c;
		}else if(num[s]!=c){
			ok=false;
		}
	}
	if(num[0]==0)ok=false;
	if(ok){
		rep(i,n)cout<<num[i];
		cout<<endl;
	}
	else{
		cout<<-1<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}
