#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> p(M);
  int x = 0;
  for (int i = 0; i < M; i++) {
    int X;
    char Y;
    cin >> X >> Y;
    p[i] = make_pair(X, Y);
    x = max(x, p[i].first);
  }
  if (x == 1 && N == 1) {
    for (int i = 0; i < 10; i++) {
      string s;
      s = to_string(i);
      bool flag = true;
      for (int j = 0; j < M; j++) {
        if (s[p[j].first - 1] != p[j].second) flag = false;
      }
      if (flag) {
        cout << i << endl;
        return 0;
      }
    }
  }
  if (x == 2 && N == 2) {
    for (int i = 10; i < 100; i++) {
      string s;
      s = to_string(i);
      bool flag = true;
      for (int j = 0; j < M; j++) {
        if (s[p[j].first - 1] != p[j].second) flag = false;
      }
      if (flag) {
        cout << i << endl;
        return 0;
      }
    }
  }
  if (x == 3 && N == 3) {
    for (int i = 100; i < 1000; i++) {
      string s;
      s = to_string(i);
      bool flag = true;
      for (int j = 0; j < M; j++) {
        if (s[p[j].first - 1] != p[j].second) flag = false;
      }
      if (flag) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
