#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 s[m], c[m];
  for (long long i = (long long)0; i < (long long)m; i++) cin >> s[i] >> c[i];
  int mn = (n != 1 ? pow(10, n - 1) : 0), mx = pow(10, n);
  for (long long i = (long long)mn; i < (long long)mx; i++) {
    for (long long j = (long long)0; j < (long long)m; j++) {
      int x = (int)(i / pow<int>(10, n - s[j])) % 10;
      if (x != c[j]) break;
      if (j == m - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
