#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, M;
	std::cin >> N >> M;
	
	std::map<int64_t, int64_t> number;
	for (int64_t i = 0; i < M; i++)
	{
		int64_t s, c;
		std::cin >> s >> c;
		
		if (number[s] && number[s] != c)
		{
			std::cout << "-1" << std::endl;
			return;
		}

		number[s] = c;
	}

	for (int64_t i = 1; i <= N; i++)
	{
		if(!number[i]) number[i] = 0;
	}

	if (number[1] == 0 && number[2])
	{
		std::cout << "-1" << std::endl;
		return;
	}

	for (int64_t i = 1; i <= N; i++)
	{
		std::cout << number[i];
	}
	std::cout << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}
