#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[10], c[10];
  string tmp;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int j = 0; j < 1000; j++) {
    bool flag = true;
    tmp = to_string(j);
    for (int i = 0; i < m; i++) {
      if (tmp.size() < s[i] || tmp.size() != n) {
        flag = false;
        break;
      }
      if ((tmp[s[i] - 1] - '0') == c[i])
        continue;
      else
        flag = false;
    }
    if (flag) {
      cout << j << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
