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