#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << "  " << y << endl
#define dbg3(x, y, z) cout << x << "  " << y << "  " << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    int num[n];
    f(i, 0, n){
        num[i] = 0;
    }
    int s, c;
    f(i, 0, m){
        cin >> s >> c;
        if(num[s-1] != 0 && c != num[s-1]){
            dbg("-1");
            return 0;
        }
        else{
            num[s-1] = c;
        }
    }
    
    int number = 0;
    f(i, 0, n){
        number += num[i] * ceilf(pow(10, n-i-1));
    }
    if(number < pow(10, n-1){
        if(number == 0 && n == 1){
            dbg(number);
            return 0;
        }
        dbg("-1");
        return 0;
    }
    dbg(number);
}