#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  vector<int> ans(n, 0);
  if (n != 1 && c[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (m - 1); i++) {
    for (int j = 1; j < m; j++)
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1 << endl;
          return 0;
        }
      }
  }
  for (int i = 0; i < (m); i++) {
    if (s[i] != 1) ans[0] = 1;
  }
  for (int i = 0; i < (m); i++) ans[s[i] - 1] = c[i];
  for (int i = 0; i < (n); i++) cout << ans[i];
  return 0;
}
