#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void mainsolve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> aa(n, -1);
  for (long long i = 0; i < (m); ++i) {
    long long s, c;
    cin >> s >> c;
    --s;
    if (aa[s] == -1)
      aa[s] = c;
    else {
      if (aa[s] != c) {
        cout << -1 << endl;
        return;
      }
    }
  }
  if (n > 1 && aa[0] == 0) {
    cout << -1 << endl;
    return;
  }
  long long res = 0;
  for (long long i = 0; i < (n); ++i) {
    if (aa[i] == -1) aa[i] = 0;
    res += aa[i] * pow(10, n - 1 - i);
  }
  cout << res << endl;
  return;
}
int main() {
  mainsolve();
  return 0;
}
