#include <bits/stdc++.h>
using namespace std;
int cf(int n) {
  int ans = 1;
  for (long long i = 0; i < (n); i++) {
    ans *= 10;
  }
  return ans;
}
int s[10], c[10];
int main() {
  int n, m;
  cin >> n >> m;
  for (long long i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (long long i = (cf(n - 1)); i < (cf(n)); i++) {
    bool can = true;
    for (long long j = 0; j < (m); j++) {
      if (!(i % cf(n - s[j] + 1) / cf(n - s[j]) == c[j])) {
        can = 0;
        break;
      }
    }
    if (can) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
