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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int main() {

  int M;
  int N;
  cin >> N >> M;
  int ans;
  vector<int> s(M);
  vector<char> c(M), n(9);
  REP(i, M){
    cin >> s[i] >> c[i];
    s[i]--;
  }
  if(N == 3){
    string _n = "000";
  } if(N == 2){
    string _n = "00";
  }else {
    string _n = "0";
  }
  
  vector<int> y(3, 0);
  REP(i, M){
    if(s[i] == 0 && c[i] == '0'){
      _n = "-1";
      break;
    }else {
      if(y[s[i]] != 0 && _n[s[i]] != c[i]){
        _n = "-1";
        break;
      } 
      // cout << s[i] << " ";
      _n[s[i]] = c[i];
      y[s[i]]++;
    }

  }


  cout << stoi(_n) << endl;
 

    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/
