#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <utility>
#include <map>
 
int main()
{
  	int n, m;
  	std::cin >> n >> m;
  	std::vector<int> ans(n);
  	for(auto &e:ans){
      e = -1;
    }
  	int dig;
	int val;
  	bool illegal = false;
  	int min=6;
  	for(int i=0;i<m;i++)
    {  	
      	std::cin >> dig >> val;
      	if(ans[dig-1] != -1 && ans[dig-1] != val)
        {
          	illegal = true;
          	break;
        }
      	if(val!=0) min = std::min(min, dig-1);
      	ans[dig-1] = val;
    }
  	for(int i=0;i<min && m!=0;i++)
    {
      	if(ans[i] == 0)
        {
          	illegal = true;
			break;
        }
    }
  	if(illegal || (n > 1 && m == 0))
    {
      	std::cout << -1 << "\n";
    }
  	else
    {
      	for(int i=0;i<n;i++)
    	{
      		std::cout << ((ans[i] == -1) ? 0 : ans[i]);
    	}
  		std::cout << "\n";
    }
  	return 0;
}#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <utility>
#include <map>
 
int main()
{
  	int n, m;
  	std::cin >> n >> m;
  	std::vector<int> ans(n);
  	for(auto &e:ans){
      e = -1;
    }
  	int dig;
	int val;
  	bool illegal = false;
  	int min=6;
  	for(int i=0;i<m;i++)
    {  	
      	std::cin >> dig >> val;
      	if(ans[dig-1] != -1 && ans[dig-1] != val)
        {
          	illegal = true;
          	break;
        }
      	if(val!=0) min = std::min(min, dig-1);
      	ans[dig-1] = val;
    }
  	for(int i=0;i<min && m!=0;i++)
    {
      	if(ans[i] == 0)
        {
          	illegal = true;
			break;
        }
    }
  	if(illegal || (n > 1 && m == 0))
    {
      	std::cout << -1 << "\n";
    }
  	else
    {
      	for(int i=0;i<n;i++)
    	{
      		std::cout << ((ans[i] == -1) ? 0 : ans[i]);
    	}
  		std::cout << "\n";
    }
  	return 0;
}