#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++) cin >> s.at(i) >> c.at(i);
  if (N == 1) {
    bool flag = true;
    for (int i = 0; i < M - 1; i++)
      if (c.at(i) != c.at(i + 1)) flag = false;
    if (flag)
      cout << c.at(0) << endl;
    else
      cout << -1 << endl;
    return 0;
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string tmp = to_string(i);
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (tmp.at(s.at(j) - 1) != c.at(j)) flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
