#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> a(M);
  for (int i = 0; i < M; i++) cin >> a.at(i).first >> a.at(i).second;
  sort(a.begin(), a.end());
  if (a.at(0) == make_pair(1, 0))
    cout << "-1" << endl;
  else {
    bool x = false;
    for (int i = 1; i < M; i++)
      for (int j = 0; j < i; j++) {
        if (a.at(i).first == a.at(j).first && a.at(i).second != a.at(j).second)
          x = true;
      }
    if (x)
      cout << "-1" << endl;
    else {
      vector<int> m(N, 0);
      for (int i = 0; i < M; i++) {
        m.at(a.at(i).first - 1) = a.at(i).second;
      }
      if (m.at(0) == 0 && N != 1) m.at(0) = 1;
      for (int i = 0; i < N; i++) cout << m.at(i);
      cout << endl;
    }
  }
}
