#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char> > p(M);
  for (int i = (int)(0); i < (int)(M); ++i) {
    int s;
    char c;
    cin >> s >> c;
    pair<int, char> ss;
    ss.first = s;
    ss.second = c;
    p[i] = ss;
  }
  int res = 1000;
  for (int i = (int)(1); i < (int)(1000); ++i) {
    string I = to_string(i);
    if ((int)I.size() != N) continue;
    bool b = true;
    for (int j = (int)(0); j < (int)(M); ++j) {
      pair<int, char> sc = p[j];
      if (i == 702) {
      }
      if (I[sc.first - 1] != sc.second) b = false;
    }
    if (b) res = min(res, i);
  }
  if (res == 1000)
    cout << -1 << endl;
  else
    cout << res << endl;
}
