#include <bits/stdc++.h>
using namespace std;
int aa(int n) {
  if (n == 0) return 1;
  int A;
  if (n > 0) {
    A = aa(n - 1) * 10;
  }
  return A;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> p(M);
  for (int i = 0; i < M; i++) {
    int X;
    char Y;
    cin >> X >> Y;
    p[i] = make_pair(X, Y);
  }
  for (int i = aa(N - 1); 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;
}
