#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int N, M;
int s[5], c[5];
bool ok(int i) {
  for (int m = 0; m < (int)(M); ++m) {
    int j = i;
    for (int si = 0; si < (int)(N - s[m]); ++si) j /= 10;
    if (i == 702)
      ;
    if (j % 10 != c[m]) return false;
  }
  return true;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < (int)(M); ++i) cin >> s[i] >> c[i];
  int minimum = 1;
  for (int n = 0; n < (int)(N - 1); ++n) minimum *= 10;
  int maximum = 1;
  for (int n = 0; n < (int)(N); ++n) maximum *= 10;
  int ans = -1;
  for (int i = minimum; i < maximum; ++i) {
    if (ok(i)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
