#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a >= b) return false;
  a = b;
  return true;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a <= b) return false;
  a = b;
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (long long i = (long long)0; i < (long long)n; i++) ans[i] = -1;
  for (long long i = (long long)0; i < (long long)m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[s] == -1)
      ans[s] = c;
    else if (ans[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long i = (long long)0; i < (long long)n; i++) {
    if (ans[i] == -1) {
      cout << (i == 0);
    } else
      cout << ans[i];
  }
}
