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