#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmax(T &ans, T t) {
  if (t > ans) ans = t;
}
template <class T>
inline void chmin(T &ans, T t) {
  if (t < ans) ans = t;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  map<int, int> mp;
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (!mp[s[i]]) {
      mp[s[i]] = c[i] + 1;
    } else {
      if (mp[s[i]] != c[i] + 1) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (c[i] == 0 && s[i] == 1 && n > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int j = 1; j <= n; ++j) {
    if (mp[j])
      cout << mp[j] - 1;
    else
      cout << 0;
  }
  cout << endl;
}
