module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n, m;
	int[] s, c;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		auto ar = readln().strip().split().map!(to!int).array();
		n = ar[0].to!int;
		m = ar[1].to!int;
        foreach (i; 0..m)
        {
    		ar = readln().strip().split().map!(to!int).array();
            s ~= ar[0];
            c ~= ar[1];
        }
	}
}

auto main2(Input* input)
{
	with (input)
	{
        int[] result;
        result.length = n;
        result[] = -1;
        foreach (i, ss; s)
        {
            if (result[ss-1] != -1 && result[ss-1] != c[i])
                return -1;
            result[ss-1] = c[i];
        }
        if (result[0] == 0)
        {
            if (n == 1)
                return 0;
            else
                return -1;
        }
        if (n == 1 && result[0] == -1)
            return 0;
        foreach (i, ref r; result)
        {
            if (i == 0)
            {
                if (r == -1) r = 1;
            }
            else
            {
                if (r == -1) r = 0;
            }
        }

        int intResult = 0;
        foreach (r; result)
        {
            intResult *= 10;
            intResult += r;
        }
        return intResult;
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`3 3
1 7
3 2
1 7`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 702);
	}

	unittest // example2
	{
		string example =
`3 2
2 1
2 3`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == -1);
	}

	unittest // example3
	{
		string example =
`3 1
1 0`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == -1);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}
