#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char> > r(M);
  int a;
  char b;
  for (int i = 0; i < (int)(M); i++) {
    cin >> a;
    cin >> b;
    a--;
    r[i].first = a;
    r[i].second = b;
  }
  int s, t;
  if (N == 1) {
    s = 1;
    t = 10;
  } else if (N == 2) {
    s = 10;
    t = 100;
  } else {
    s = 100;
    t = 1000;
  }
  bool f = false;
  for (int i = s; i < (int)(t); i++) {
    f = false;
    string s = to_string(i);
    for (int j = 0; j < (int)(M); j++)
      if (s[r[j].first] != r[j].second) {
        f = true;
        break;
      }
    if (f) continue;
    cout << i << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
