#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s, c;
  string moji;
  vector<pair<int, int>> data(M);
  for (int i = (int)(0); i < (int)(M); ++i) {
    cin >> s >> c;
    data[i].first = s - 1;
    data[i].second = c;
  }
  for (int i = (int)(1); i < (int)(1000); ++i) {
    moji = to_string(i);
    bool b = true;
    if (moji.size() != N) {
      continue;
    }
    for (int j = (int)(0); j < (int)(M); ++j) {
      if ((moji[data[j].first] - '0') != data[j].second) {
        b = false;
      }
    }
    if (b) {
      cout << moji << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
