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