#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  long long int res = 1LL;
  while (y) {
    if (y & 1) {
      res = (res * x) % 1000000007;
    }
    x = (x * x) % 1000000007;
    y = (y >> 1);
  }
}
long long int s[6] = {0};
long long int v[6] = {0};
long long int n, m;
vector<long long int> z;
long long int check(long long int i) {
  z.clear();
  long long int k = i;
  while (k) {
    z.push_back(k % 10);
    k /= 10;
  }
  if (z.size() != n) return 0;
  for (long long int i = 1; i <= m; i += 1) {
    long long int x = s[i];
    long long int y = v[i];
    if (z[n - s[i]] != v[i]) return 0;
  }
  return 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<long long int> lol(n, -1);
  long long int f = 1;
  for (long long int i = 1; i <= m; i += 1) {
    cin >> s[i] >> v[i];
  }
  for (long long int i = 1; i <= 1000; i += 1) {
    if (check(i)) {
      cout << i << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
  return 0;
}
