#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  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 a;
  int ans = 10000;
  int b, b2;
  int d = int(pow(10, N));
  int e = int(pow(10, N - 1));
  for (int j = e; j < d; j++) {
    a = 0;
    for (int i = 0; i < (M); ++i) {
      b = int(pow(10, (N - s[i] + 1)));
      b2 = int(pow(10, (N - s[i])));
      if ((j % b) / b2 != c[i]) a++;
    }
    if (a == 0) {
      ans = j;
      break;
    }
  }
  if (ans == 10000)
    cout << -1;
  else
    cout << ans;
}
