#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, x;
  char c;
  cin >> N >> M;
  vector<char> t(N, '0');
  string r = "";
  set<int> y;
  for (int i = 0; i < (M); ++i) {
    cin >> s >> c;
    if (s > N || (y.count(s) && t.at(s - 1) != c)) {
      cout << -1 << endl;
      return 0;
    }
    y.insert(s);
    t.at(s - 1) = c;
  }
  for (int i = 0; i < (N); ++i) r += t.at(i);
  x = stoi(r);
  if (x < pow(10, N - 1)) {
    cout << -1 << endl;
    return 0;
  }
  cout << x << endl;
}
