#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const int MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  int N, M;
  cin >> N >> M;
  vector<int> S(N, -1);
  for (int i = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (S[s] == -1 || S[s] > c) {
      S[s] = c;
    }
  }
  if (S[0] == -1 || S[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  string ans = "";
  for (int i = 0; i < (N); i++) {
    if (S[i] == -1) {
      ans += "0";
    } else {
      ans += to_string(S[i]);
    }
  }
  cout << ans << endl;
}
