#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>

using namespace std;

using ll = long long;
using ld = long double;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M; cin >> N >> M;
    vec<int> ns(N, -1);
    REP(i, 0, M)
    {
        int s, c; cin >> s >> c; --s;

        if (ns[s] != -1 && ns[s] != c)
        {
            cout << -1 << endl;
            return 0;
        }

        ns[s] = c;
    }

    if (N == 1)
    {
        cout << (ns[0] == -1 ? 0 : ns[0]) << endl;
        return;
    }

    bool topFilled = false;
    REP(i, 0, N)
    {
        if (!topFilled && ns[i] == 0)
        {
            cout << -1 << endl;
            return 0;
        }

        cout << (ns[i] == -1 ? (topFilled ? 0 : 1) : ns[i]);
        topFilled = true;
    }

    return 0;
}
