#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> ans(n);
  for (int i = 0; i < (n); i++) ans[i] = -1;
  for (int i = 0; i < (m); i++) {
    if (ans[s[i]] != -1 && ans[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      ans[s[i]] = c[i];
    }
  }
  for (int i = 0; i < (n); i++) {
    if (ans[i] == -1) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << ans[i];
    }
    if (i == n - 1) cout << endl;
  }
  return 0;
}
