#define SET

// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <string>
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (long long i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define srt(v) sort(v.begin(), v.end())
#define rev_srt(v) sort(v.rbegin(), v.rend())
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;

#ifdef SET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multi_set;

#endif

#define nl '\n'
#define sp " "
#define precision(x) cout << fixed << setprecision(x);
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define MX 100005
#define MOD 1000000007
/*ll fac[MX], modInv[MX];

ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{

    if (r == 0)
        return 1;
    if (n < r)
        return 1;

    return ((((fac[n] * modInv[r]) % p) *
             modInv[n - r]) %
            p);
}

void pre()
{
    fac[0] = 1;
    for (ll i = 1; i < MX ; i++)
        fac[i] = (fac[i - 1] * i) % MOD;
    f(i, 0, MX )
        modInv[i] = modInverse(fac[i], MOD);
}*/

template <class T>
inline bool remax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T>
inline bool remin(T &a, T b) { return a > b ? a = b, 1 : 0; }

ll md = 1000000007;
//ll fact[1000005], mi[1000005];
//; // expt[1000005];
ll my_gcd(ll n, ll m)
{
    if (n % m == 0)
        return m;
    if (n < m)
        swap(n, m);
    while (m > 0)
    {
        n = n % m;
        swap(n, m);
    }
    return n;
}

ll pw(ll a, ll b)
{
    ll c = 1, m = a % md;
    while (b)
    {
        if (b & 1)
            c = (c * m) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}

ll modinv(ll n)
{
    return pw(n, md - 2);
}

inline ll add(ll a, ll b) { return (md + a % md + b % md) % md; }
inline ll subt(ll a, ll b) { return (a % md - b % md + md) % md; }
inline ll mult(ll a, ll b) { return (1ll * (a % md) * (b % md)) % md; }

/*ll ncr(int n, int r)
{
    if (!n)
        return 1;
    return mult(fact[n], mult(mi[r], mi[n - r]));
}
void pre()
{
    fact[0] = 1;
    f(i, 1, 2003) fact[i] = mult(i, fact[i - 1]);
    f(i, 0, 2003) mi[i] = modinv(fact[i]);
}
*/
int myceil(int a, int b)
{
    if (a % b)
        return (a / b) + 1;
    else
        return a / b;
};
/*
vi adj[200005];
int special[200005];
int dis1[200005],disn[200005];

void bfs(int start)
{
    int visited[200005];
    int dis[200005];
    f(i,0,200005) visited[i]=0,dis[i]=0;
    queue<int> bfq;
    bfq.push(start);
    visited[start]=1;
    while(!bfq.empty())
    {
        int cur=bfq.front();
        bfq.pop();
        for(auto i: adj[cur])
        {
            if(!visited[i])
            {
                dis[i]= dis[cur]+1;
                bfq.push(i);
                visited[i]=1;
            }
        }
    }
    if(start==1) f(i,0,200005) dis1[i]=dis[i];
    else    f(i,0,200005) disn[i]=dis[i];

}*/


void solvetestcase(int tcn)
{
    
    int n,m; cin>>n>>m;
    int num[n];
    f(i,0,n) num[i]=-1;
    f(i,0,n)
    {
        int s,c; cin>>s>>c;
        s--;
        if(s<n)
        {
            if(num[s]!=-1)
            {
                cout<<-1<<endl;
                return;
            }
            num[s]=c;
        }
    }
    if(n==1)
    {
        if(num[0]==-1) cout<<0<<endl;
        else cout<<-1<<endl;
        return;
    }
    if(num[0]==0) {cout<<-1; return;}
    for(int i=n-1;i>=0;i--)
    {
    
        if(num[i]==-1)
        {
            if(i==n-1) cout<<1;
            else
            cout<<0;  
            continue;
        }
        cout<<num[i];
    }   
    return;

}

int main()
{
    fio;
    int t = 1;
    //cin >> t;
    f(i, 1, t + 1)
    {
        solvetestcase(i);
    }
};