#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int N, M;
  bool torf = true;
  cin >> N >> M;
  vector<int> c(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (c.at(a - 1) == 0)
      c.at(a - 1) = b;
    else if (c.at(a - 1) != b)
      torf = false;
  }
  if (torf = false || c.at(0) == 0)
    cout << "-1" << endl;
  else {
    for (int i = 0; i < N; i++) {
      cout << c.at(i);
    }
    cout << endl;
  }
}
