#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long ksm(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ans = ans * a % mod;
  return ans;
}
long long a[200][2000];
long long cal(long long x) {
  if (!x) return 1;
  long long ans = 0;
  while (x) ans++, x /= 10;
  return ans;
}
pair<long long, long long> b[2000];
signed main() {
  ios::sync_with_stdio(0);
  long long n, m;
  long long ans = 1e9;
  cin >> n >> m;
  long long p[20];
  p[0] = 1;
  for (long long i = 1; i <= 3; i++) p[i] = p[i - 1] * 10;
  for (long long i = 1; i <= m; i++) cin >> b[i].first >> b[i].second;
  for (long long i = 0; i <= 999; i++) {
    if (cal(i) == n) {
      long long cnt = 0;
      for (long long j = 1; j <= m; j++) {
        cnt += b[j].second == (i / p[b[j].first - 1]) % 10;
      }
      if (cnt == m) {
        ans = min(ans, i);
      }
    }
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
  getchar();
  getchar();
}
