#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  vector<int> num(N);
  for (int(i) = 0; (i) < (N); (i)++) num[i] = -1;
  for (int(i) = 0; (i) < (M); (i)++) {
    cin >> s[i] >> c[i];
  }
  for (int(i) = 0; (i) < (M); (i)++) {
    if (num[s.at(i) - 1] == -1 || num[s.at(i) - 1] == c.at(i)) {
      num[s.at(i) - 1] = c.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    if (num[i] == -1) num[i] = 0;
    cout << num[i];
  }
  cout << '\n';
}
