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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <ll>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

void solve() {

    ll N,M;
    ll s[5],c[5];
    cin >> N >> M;
    REP(i,M){
        cin >> s[i] >> c[i];
    }

    if(N==1)
    {
        ll a = c[0];
        FOR(i,1,M){
            if(c[i] != a){
                cout << "-1";
                return;
            }
        }
        cout << a;
    } else if(N==2)
    {
        ll a[2] = {-1,-1};
        REP(i,M){
            if(a[s[i]-1] != -1 && a[s[i]-1] != c[i]){
                cout << "-1";
                return;
            }else{
                a[s[i]-1] = c[i];
            }            
        }
        if(a[0] == 0){
            cout << "-1";
            return;
        }
        if(a[0] == -1){
            a[0] = 1;
        } 
        if(a[1] == -1){
            a[1] = 0;
        }
        cout << a[0] << a[1] << endl;
    }
    else if(N==3)
    {
        ll a[3] = {-1,-1,-1};
        REP(i,M){
            if(a[s[i]-1] != -1 && a[s[i]-1] != c[i]){
                cout << "-1";
                return;
            }
                            a[s[i]-1] = c[i];            
        }

        if(a[0] == 0){
            cout << "-1";
            return;
        }
        
        if(a[0] == -1){
            a[0] = 1;
        } 
        if(a[1] == -1){
            a[1] = 0;
        }
        if(a[2] == -1){
            a[2] = 0;
        }
        cout << a[0] << a[1] << a[2];
    }   
}

signed main() {
    

    solve();

    return 0;
}