#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1 << 29;
const long long INFL = 1LL << 60;
const long long mod = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> b(10, -1);
  for (int i = 0; i < int(m); i++) {
    int c, d;
    cin >> c >> d;
    c--;
    if (c == 0 && d == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (b[c] == -1) {
      b[c] = d;
    } else if (b[c] != d) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < int(10); i++) {
    if (b[i] == -1) b[i] = 0;
  }
  if (b[0] == 0) {
    b[0] = 1;
  }
  for (int i = 0; i < int(n); i++) cout << b[i];
  cout << endl;
}
