#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1LL << 60;
const int INF = 1001001001;
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> V(n + 1, INF);
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    V[a] = min(V[a], b);
  }
  bool check = false;
  for (int i = 1; i <= (n); i++) {
    if (V[i] != INF && V[i] != 0) {
      check = true;
    }
    if (V[i] == INF || V[i] == 0) {
      if (check)
        V[i] = 0;
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i <= (n); i++) {
    cout << V[i];
  }
  cout << endl;
  return 0;
}
