#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M], ans[N];
  for (int i = 0; i < N; i++) ans[i] = 0;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (ans[s[i] - 1] == 0)
      ans[s[i] - 1] = c[i];
    else if (ans[s[i] - 1] > c[i])
      ans[s[i] - 1] = c[i];
  }
  if (N == 1 && ans[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (ans[0] == 0)
    cout << -1 << endl;
  else {
    int answer = 0;
    for (int i = 0; i < N; i++) answer += ans[i] * pow(10, N - i - 1);
    cout << answer << endl;
  }
  return 0;
}
