#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = (0); i < (M); ++i) cin >> s[i] >> c[i];
  int tmp = pow(10, N - 1);
  int end = tmp * 10;
  while (tmp != end) {
    string S = to_string(tmp);
    int cnt = 0;
    for (int i = (0); i < (M); ++i) {
      if (S[s[i] - 1] == (char)c[i] + '0') cnt++;
    }
    if (cnt == M) {
      cout << tmp << endl;
      return 0;
    }
    tmp++;
  }
  cout << -1 << endl;
  return 0;
}
