#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a = pow(10, n);
  string str = to_string(a);
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int j = 0; j < stoi(str); j++) {
    bool flag = true;
    for (int k = 0; k < m; k++) {
      if (to_string(j).length() < s.at(k)) {
        flag = false;
        break;
      }
      if (to_string(j).at(s.at(k) - 1) - '0' != c.at(k)) {
        string test1 = to_string(j);
        int test = (to_string(j).at(s.at(k) - 1));
        flag = false;
        break;
      }
    }
    if (flag == true) {
      cout << j;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
