#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{
 //   io
    int n, m;
    cin >> n >> m;
    bool dig[n+1] = {false};
    int grid[m][2];
    for(int i = 0; i < m; i++)
    {
        int s,c;
        cin >> s >> c;
        grid[i][0] = s;
        grid[i][1] = c;
    }
    int *arr = new int[n+1]();
    int flag = 0;
    for(int i = 0; i < m; i++)
    {
        int pos = grid[i][0],val = grid[i][1];
        if(n!=1)
        {
            if(pos == 1 && val == 0)
            {
                flag = 1;
                break;
            }
        }
            if(!dig[pos])
            {
                arr[pos] = val;
                dig[pos] = true;
  //              cout << pos << " " << arr[pos];
            }
            else if(dig[pos] && val!=arr[pos])
            {
                flag = 1;
                break;
            }
    //    for(int i = 1; i <= n; i++)
    //         cout << arr[i];
    //     cout << "\n"; 
    }
    if(flag)
        cout << "-1\n";
    else{
        for(int i = 1; i <= n; i++)
            cout << arr[i];
        cout << "\n";
    }
    return 0;
}