#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n);
  for (int i = 0; i < (n); ++i) num[i] = 0;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i < (m); ++i) {
    if (num[s[i]] != 0 && num[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    num[s[i]] = c[i];
  }
  if (n > 1 && num[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) cout << num[i];
  cout << endl;
  return 0;
}
