#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> ans(N, 100);
  for (int i = 0; i < M; ++i) {
    ans[s[i]] = (ans[s[i]] > c[i]) ? c[i] : ans[s[i]];
  }
  if (ans[0] == 100 || ans[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < N; ++i) {
    if (ans[i] == 100)
      cout << "0";
    else
      cout << ans[i];
  }
  cout << endl;
  return 0;
}
