#include <bits/stdc++.h>
using namespace std;
void no() {
  cout << -1 << endl;
  exit(0);
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (n > 1 && s[i] == 0 && c[i] == 0) {
      no();
    }
  }
  for (long long i = 0; i < pow(10, n); i++) {
    string t = to_string(i);
    for (long long j = 0; j < m; j++) {
      if (t[s[j]] - '0' != c[j]) {
        break;
      }
      if (j == m - 1) {
        cout << t << endl;
        exit(0);
      }
    }
  }
  no();
}
