#include <bits/stdc++.h>
using namespace std;
static const int MAX = 10000;
static const long long INFTY = 1e12;
struct edge {
  long long 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);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  string _n;
  if (N == 3) {
    _n = "000";
  } else if (N == 2) {
    _n = "00";
  } else {
    _n = "0";
  }
  vector<int> y(3, 0);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    if (s[i] == 0 && c[i] == '0') {
      _n = "-1";
      break;
    } else {
      if (y[s[i]] != 0 && _n[s[i]] != c[i]) {
        _n = "-1";
        break;
      }
      _n[s[i]] = c[i];
      y[s[i]]++;
    }
  }
  cout << stoi(_n) << endl;
}
