#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
typedef vector<long long> V;
typedef vector<V> VV;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
void solve(int a) { cout << (a ? "Yes" : "No") << endl; }
int main()
{
    int n, m;
    int ans = 0;
    cin >> n >> m;
    int a, b;
    vector<int> c(n+1,10);
    int d = 1;
  
    rep(i, m)
    {
        cin >> a >> b;
        if (c[a] == b or c[a] == 10)
        {
            c[a] = b;
        }
        else
        {
            ans = -1;
        }
    }
    if(n!=1 and c[1]==0){
        ans=-1;
    }
    if (ans != -1)
    {

        for(int i=n;i>=0;i--)
        {

            if (c[i] != 10)
            {
                ans += c[i] * d;
            }
            if(i==0 and c[i]==0){
                ans+=1*d
            }
            d *= 10;
        }
    }
    cout << ans << endl;
}