#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n, m, x, y;
    cin >> n >> m;
    map<int, int> mp;
    bool A[n + 1] = {false};
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        if (!A[x])
        {
            mp[x] = y;
            A[x] = true;
        }
        else
        {
            if (x == n && y == 0)
                continue;
            else
                mp[x] = min(mp[x], y);
        }
    }
    if (!A[n])
    {
        cout << -1;
        return;
    }
    for (int i = 1; i <= n; i++)
        cout << mp[i];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}