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