#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  vector<int> s(M), c(M);
  cin >> N >> M;
  for (int i = 0; i < (M); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < (M); ++i) {
    if (ans[s[i]] != 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i]] = c[i];
  }
  bool can = false;
  for (int i = 0; i < (N); ++i) {
    if (!can && ans[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[i] != 0) can = true;
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
