#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1 & m == 0) {
    cout << -1 << endl;
    return 0;
  }
  int s[m];
  char c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 & c[i] == '0') {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i <= 703; i++) {
    int cnt = 0;
    string s_i = to_string(i);
    for (int j = 0; j < m; j++) {
      if (s_i.length() < s[j]) continue;
      if (s_i[s[j] - 1] == c[j]) {
        cnt++;
      }
    }
    if (cnt == m & s_i.length() == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
