#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
int keta(int num) {
  int res = 0;
  while (num > 0) {
    num /= 10;
    res++;
  }
  return res;
}
bool check(int num, vector<int> s, vector<int> c, int N) {
  if (N != keta(num)) return false;
  int M = s.size();
  string str = "";
  while (num > 0) {
    str = ((char)('0' + num % 10)) + str;
    num /= 10;
  }
  for (int(i) = 0; (i) < (M); (i)++) {
    if (str[s[i] - 1] - '0' != c[i]) {
      return false;
    }
  }
  return true;
}
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];
  for (int i = 0; i <= 999; i++) {
    if (check(i, s, c, N)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
