#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  bool sw = 1;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 and c[i] == 0) {
      sw = 0;
    }
  }
  if (!sw and n != 1) {
    cout << "-1\n";
    return 0;
  }
  if (!sw) {
    cout << "0\n";
  }
  int a[n + 1];
  bool ch[n + 1];
  for (int i = 0; i <= n; i++) {
    a[i] = 0;
    ch[i] = 0;
  }
  if (n != 1) a[1] = 1;
  for (int i = 0; i < m; i++) {
    if (ch[s[i]]) {
      if (a[s[i]] != c[i]) {
        cout << "-1\n";
        return 0;
      }
    } else {
      a[s[i]] = c[i];
      ch[s[i]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i];
  }
  cout << "\n";
  return 0;
}
