#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
const int mod = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(N);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<int> num(N, -1);
  for (int i = 0; i < (int)(M); i++) {
    if (num[s[i]] == -1 || num[s[i]] == c[i]) {
      num[s[i]] = c[i];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (num[0] == 0 && N != 1) {
    cout << "-1" << endl;
    return 0;
  } else if (num[0] == 0) {
    cout << "0" << endl;
    return 0;
  }
  if (num[0] == -1) {
    num[0] = 1;
  }
  for (int i = 0; i < (int)(N); i++) {
    if (num[i] == -1) {
      num[i] = 0;
    }
    cout << num[i];
  }
  cout << endl;
}
