#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	bool z = true;
	
	int n, m;
	cin >> n >> m;
	int x[3] = { -1,-1,-1 };
	rep(i, m)
		{
			cin >> a >> b;
			if (n!=1&&a==1 && b==0)
			{
				z = false;
			}
			if (x[a-1+3-n] != -1&&x[a-1+3-n]!=b)
			{
				z = false;
			}
			else
				x[a-1+3-n] = b;
		}
	rep(i, 3)
		{
			if (x[i] == -1)
				x[i] = 0;
		}
	if (z)
		cout << x[0]*100+x[1]*10+x[2] << endl;
	else
		cout << -1<<endl;
		
	return 0;
}