#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> tmp(N, 9);
  vector<bool> flag(N, false);
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    flag[s] = true;
    tmp[s] = min(tmp[s], c);
  }
  if (flag[0] == false or tmp[0] == 0)
    cout << -1 << endl;
  else {
    for (int i = (0); i < (N); ++i) {
      if (flag[i] == true)
        cout << tmp[i];
      else
        cout << 0;
    }
    cout << endl;
  }
  return 0;
}
