#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n,m;
    cin >> n >> m;
    bool flag = true;
    vec<int> num(n,-1);
    int s,c;
    while(cin >> s >> c)
    {
        s--;
        if (num[s]!= -1 and num[s] != c)
        {
            flag = false;
            break;
        }
        else
        {
            num[s] = c;
        }
    }
    if (flag)
    {
        num[0] = max(num[0],1);
        for (auto &&e : num)
        {
            e = max(0,e);
        }
        auto sum = accumulate(num.begin(),num.end(),0,[](auto a,auto b)
        {
            return a*10+b;
        });
        cout << sum << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    
    
}