#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[i] >> c[i];
  long long ans = -1;
  int b = pow(10, n);
  if (n == 1) {
    for (int i = pow(10, n - 1) - 1; i < b; i++) {
      string answer = to_string(i);
      int j = 0;
      while (j < m) {
        if (answer[s[j] - 1] != c[j]) break;
        j++;
      }
      if (m == 0 || j == m - 1) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  if (n != 1) {
    for (int i = pow(10, n - 1); i < b; i++) {
      string answer = to_string(i);
      int j = 0;
      while (j < m) {
        if (answer[s[j] - 1] != c[j]) break;
        j++;
      }
      if (m == 0 || j == m - 1) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
}
