#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int n , m ,flag = 1;
    cin>>n>>m;
    int arr[n+1] = { 0 } , mark[n+1] = { 0 };
    while(m--)
    {
        int i , d;
        cin>>i>>d;
        if(mark[i]==0)
        {
            arr[i] = d;
            mark[i]=1;
        } else if(mark[i]==1&&d!=arr[i])
        {
            flag = 0;
            break;
        }
    }
    if(arr[1]==0&&n>1)
    flag = 0;
    if(flag == 0)
    {
        cout<<"-1";
    } else {
        for(int i = 1 ; i<=n;i++)
        {
            cout<<arr[i];
        }
    }
}
