#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
int exponential(int a, int b) {
  int sum = 1;
  if (b != 0) {
    for (int i = 0; i < b; i++) {
      sum *= a;
    }
  }
  return sum;
}
int main() {
  int n, m;
  cin >> n >> m;
  vi s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int n0 = exponential(10, n - 1);
  int nend = exponential(10, n);
  int ans = -1;
  for (int i = n0; i < nend; i++) {
    bool issc = true;
    string str = to_string(i);
    for (int j = 0; j < m; j++) {
      if (str[s[j] - 1] != c[j]) {
        issc = false;
      }
    }
    if (issc) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
