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

void print_vector(vector<bool> firstTime)
{
    for(int i = 0; i < firstTime.size(); i++)
    {
        cout << firstTime[i] << " " ;
    }
    cout << endl;
}
void print_vector(vector<int> firstTime)
{
    for(int i = 0; i < firstTime.size(); i++)
    {
        cout << firstTime[i] << " " ;
    }
    cout << endl;
}

int main()
{
    int N, M;
    cin >> N >> M;
    // vector<vector<int>>vals(M, vector<int>(2));
    map<int, vector<int>>m;
    int pos, val;
    for(int i = 0; i < M; i++)
    {
        // cin >> vals[i-1][0] >> vals[i-1][1];
        cin >> pos >> val;
        // vals[pos - 1][0] = pos - 1;
        // vals[pos - 1][1] = val;
        m[i] = {pos - 1, val}; 
    }

    // for(int i = 0; i < M; i++)
    // {
    //     cout << vals[i][0] << " " << vals[i][1] << endl;
    // }
    vector<int> fillup(N, 0);
    vector<bool> first_time(N, false);
    for(auto it = m.begin(); it != m.end(); it++)
    {
        int pos = it->second[0];
        // If already present
        if(fillup[pos] != it->second[1] && first_time[pos])
        {
            cout << -1 << endl;
            return 0;
        }
        else    
        {
            fillup[pos] = it->second[1]; 
            first_time[pos] = true;
        // }
        // cout << "FILUP" << endl ;
        // print_vector(fillup);
        // cout << "FIRST TIME" << endl ;
        // print_vector(first_time);
    }

    string returningthis = "";
    for(int i = 0; i < N; i++)
    {
        if(fillup[i] == 0)
        {
            returningthis += '0';
        }
        else
        {
            returningthis += to_string(fillup[i]);
        }
    }

    // CHECK FOR LEAEDNIGN ZEROS
    int total_leading_zeros = 0;
    bool anything_else = false;
    for(int i = 0; i < returningthis.size(); i++)
    {
        if(returningthis[i] == '0' && anything_else == false)
        {
            total_leading_zeros ++;
        }
        else
        {
            anything_else = true;
        }
        
    }

    if(total_leading_zeros >= 1) 
    {
        cout << -1 << endl;
        return 0;
    }

    cout << returningthis << endl;


    return 0;
}