#include <bits/stdc++.h>
using namespace std;
int main() {
  int isGuess = 0;
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    int quo = isGuess / pow(10, N - s);
    if (quo != 0 && quo > c) {
      int rem = isGuess % 1 * pow(10, N - s);
      isGuess = rem;
      isGuess += c * pow(10, N - s);
    } else if (quo == 0) {
      isGuess += c * pow(10, N - s);
    }
  }
  int quo2 = isGuess / pow(10, N - 1);
  cout << isGuess << endl;
  if (quo2 != 0)
    cout << isGuess << endl;
  else
    cout << -1 << endl;
}
