#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int M;
  cin >> N;
  cin >> M;
  vector<vector<int>> c(M, vector<int>(2));
  int tmp;
  for (int i = 0; i < M; i++) {
    cin >> tmp;
    c.at(i).at(0) = tmp;
    cin >> tmp;
    c.at(i).at(1) = tmp;
  }
  vector<int> chk(N + 1);
  int res;
  bool flag = true;
  for (int i = 0; i < M; i++) {
    if (c.at(i).at(0) == N && c.at(i).at(1) == 0) {
      flag = false;
      break;
    } else if (chk.at(c.at(i).at(0)) > 0 &&
               chk.at(c.at(i).at(0)) != c.at(i).at(1)) {
      flag = false;
      break;
    } else {
      chk.at(c.at(i).at(0)) = c.at(i).at(1);
    }
  }
  if (flag == false) {
    res = -1;
    cout << res << endl;
  } else if (chk.at(1) == 0) {
    res = -1;
    cout << res << endl;
  } else {
    for (int i = 1; i <= N; i++) {
      cout << chk.at(i);
    }
    cout << endl;
  }
}
