#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  string d;
  set<int> S;
  map<int, char> ma;
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (int)(M); i++) {
    int a = s[i] - 1;
    char b = c[i];
    if (ma.count(a) && ma.at(a) != b) {
      cout << -1 << endl;
      return 0;
    }
    ma[a] = b;
    d[a] = b;
  }
  if (d[0] == '0' && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(N); i++) {
    if (d[i] >= 48 && d[i] <= 57) {
    } else {
      d[i] = '0';
    }
  }
  for (int i = 0; i < (int)(N); i++) {
    cout << d[i];
  }
  cout << endl;
  return 0;
}
