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