#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int flag = 0;
  if (n == 0) {
    for (int i = 0; i < 10; i++) {
      flag = 0;
      for (int j = 0; j < m; j++) {
        int k = 0;
        k = i / pow(10, n - s[j]);
        if (c[j] != k % 10) {
          flag = 1;
        }
      }
      if (flag == 0) {
        cout << i << endl;
        return 0;
      }
    }
  } else {
    for (int i = pow(10, (n - 1)); i < pow(10, n); i++) {
      flag = 0;
      for (int j = 0; j < m; j++) {
        int k = 0;
        k = i / pow(10, n - s[j]);
        if (c[j] != k % 10) {
          flag = 1;
        }
      }
      if (flag == 0) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
