#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
vector<int> vi;
int main() {
  int N, M;
  cin >> N >> M;
  vi.resize(N);
  for (int i = 0; i < (int)(N); i++) vi[i] = -1;
  for (int i = 0; i < (int)(M); i++) {
    int s, c, idx;
    cin >> s >> c;
    s--;
    if (vi[s] != -1 && vi[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    vi[s] = c;
  }
  if (N == 1 && vi[0] == 0) {
    cout << 0 << endl;
    return 0;
  } else if (vi[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(N); i++) {
    if (i == 0 && vi[i] == -1) {
      cout << 1;
    } else {
      if (vi[i] == -1) {
        cout << 0;
      } else {
        cout << vi[i];
      }
    }
  }
  cout << endl;
}
