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