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