#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int ans = 1000;
  int ma = 0;
  for (int i = 0; i < pow(10, n); i++) {
    int ima = i;
    int ma = 0;
    for (int h = 0; h < m; h++) {
      if (s.at(h) == 1 && c.at(h) == 0 && n != 1) {
        cout << "-1" << endl;
        return 0;
      } else {
        int now = i;
        for (int k = 0; k < n - s.at(h); k++) {
          now /= 10;
        }
        if ((now % 10) == c.at(h))
          ma += 1;
        else
          break;
      }
    }
    if (ma == m) {
      ans = ima;
      break;
    } else
      int unkoo = 0;
  }
  if (ans < 1000)
    cout << ans << endl;
  else
    cout << "-1" << endl;
}
