#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> c(b);
  vector<int> d(b);
  bool can = true;
  vector<int> e(a, 0);
  vector<int> f(a, 0);
  for (int i = 0; i < b; i++) {
    cin >> c[i] >> d[i];
    if (c[i] - 1 == 0 && d[i] == 0) {
      can = false;
    }
  }
  if (can) {
    for (int i = 0; i < b; i++) {
      if (e[c[i] - 1] == 0 && f[c[i] - 1] == 0) {
        e[c[i] - 1] = d[i];
        f[c[i] - 1]++;
      } else if (e[c[i] - 1] == d[i]) {
        f[c[i] - 1]++;
        continue;
      } else {
        can = false;
        break;
      }
    }
  }
  if (e[0] == 0) {
    e[0] == 1;
  }
  int ans = 0;
  for (int i = 0; i < a; i++) {
    ans += e[i] * pow(10, a - i - 1);
  }
  if (can) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
