#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int mi = pow(10, N - 1);
  if (mi == 1) mi = 0;
  int ans = -1;
  for (int i = mi; i < mi * 10; ++i) {
    string str = to_string(i);
    int ok = true;
    for (int j = 0; j < M; ++j) {
      if (str[s[j]] != '0' + c[j]) ok = false;
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
