#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
int main(int argc, char* argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> num(n, 10);
  for (int i = 0; i < m; i++) {
    if (num[s[i] - 1] != 10 && num[s[i] - 1] != c[i] ||
        s[i] == 1 && c[i] == 0 && n != 1) {
    fin:
      cout << "-1" << endl;
      return 0;
    }
    num[s[i] - 1] = c[i];
  }
  for (int i = 0; i < n; i++) {
    if (num[i] == 10) num[i] = 0;
    cout << num[i];
  }
  cout << endl;
  return 0;
}
