#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> out;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  bool ff = false;
  for (int i = 1; i <= N; i++) {
    bool f = true;
    vector<int> xxx;
    for (int j = 0; j < M; j++) {
      if (s[j] == i) {
        xxx.push_back(c[j]);
      }
    }
    if (xxx.size() == 0) {
      out.push_back(0);
    } else if (xxx.size() == 1) {
      out.push_back(xxx[0]);
    } else {
      for (int j = 1; j < xxx.size(); j++) {
        if (xxx[0] != xxx[j]) f = false;
      }
      out.push_back(xxx[0]);
    }
    if (!f) {
      ff = false;
      break;
    } else
      ff = true;
  }
  if (ff) {
    int ans = 0;
    int aaa = 1;
    for (int i = N - 1; i >= 0; i--) {
      ans += out[i] * aaa;
      aaa *= 10;
    }
    if (pow(10, N - 1) <= ans && ans < pow(10, N))
      cout << ans << "\n";
    else
      cout << -1 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
