#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<pair<int, int>> v(M);
  for (int i = 0; i < M; i++) {
    cin >> v.at(i).first;
    cin >> v.at(i).second;
  }
  bool mujun = 0;
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (v.at(i).first == v.at(j).first && v.at(i).second != v.at(j).second) {
        mujun = 1;
        break;
      }
    }
  }
  bool top0 = 0;
  for (int i = 0; i < M; i++) {
    if (v.at(i).first == 1 && v.at(i).second == 0) {
      top0 = 1;
      break;
    }
  }
  if (!mujun && !top0) {
    string T = "";
    for (int i = 0; i < N; i++) {
      T += '0';
    }
    for (int i = 0; i < M; i++) {
      T.replace(v.at(i).first - 1, 1, to_string(v.at(i).second));
    }
    if (T.at(0) == '0' && N > 1) {
      T.replace(0, 1, "1");
      cout << stoi(T) << endl;
    } else if (T.at(0) == '0' && N == 1) {
      cout << 0 << endl;
    } else {
      cout << stoi(T) << endl;
    }
  } else {
    cout << -1 << endl;
  }
}
