#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M, i, error = 0;
  cin >> N >> M;
  vector<int> ans(N, 0), count(N, 0);
  vector<vector<int> > data(M, vector<int>(2));
  for (int i = (int)(0); i < (int)(M); i++)
    cin >> data.at(i).at(0) >> data.at(i).at(1);
  for (int i = (int)(0); i < (int)(M); i++) {
    if (data.at(i).at(0) == 1 && data.at(i).at(1) == 0) error++;
    if (count.at(data.at(i).at(0) - 1) == 0) {
      ans.at(data.at(i).at(0) - 1) = data.at(i).at(1);
      count.at(data.at(i).at(0) - 1)++;
    } else {
      if (ans.at(data.at(i).at(0) - 1) != data.at(i).at(1)) {
        error++;
      }
    }
  }
  if (N != 1 && ans.at(0) == 0) ans.at(0)++;
  if (error != 0)
    cout << -1;
  else
    for (int i = (int)(0); i < (int)(N); i++) cout << ans.at(i);
  cout << endl;
}
