#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double eps = 1e-8;
int pow(int a, int k) {
  int ret = 1;
  for (int i = 0; i < k; ++i) ret *= a;
  return ret;
}
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];
  int l = pow(10, N - 1);
  for (int i = l; i < l * 10; ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      string t = to_string(i);
      if (t[s[j] - 1] - '0' != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
