#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> t(n + 1);
  for (int i = 0; i < (m); ++i) {
    int s;
    int c;
    cin >> s >> c;
    if (t[s] == 0) {
      t[s] = c;
    } else {
      if (t[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n != 1 && t[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n != 1 && t[1] == 0) {
    t[1] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    cout << t[i];
  }
  cout << endl;
  return 0;
}
