#include <bits/stdc++.h>
using namespace std;
using intpair = pair<int, int>;
int main() {
  string res = "000";
  int n, m;
  cin >> n >> m;
  vector<intpair> hint(m);
  bool checked[3] = {0, 0, 0};
  bool is_violated = false;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) is_violated = true;
    if (checked[s]) {
      for (int j = 0; j < (int)(i); j++) {
        if (hint[j].first == s && hint[j].second != c) {
          is_violated = true;
        }
      }
    }
    checked[s] = true;
    hint[i] = intpair(s, c);
  }
  if (is_violated) {
    cout << -1 << endl;
    return 0;
  }
  sort((hint).rbegin(), (hint).rend());
  for (int i = 0; i < (int)(m); i++) res[hint[i].first] = hint[i].second + '0';
  cout << stoi(res) / pow(10, 3 - n) << endl;
}
