#include <bits/stdc++.h>
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans.at(i) = -1;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    } else if (ans.at(s - 1) == -1 || ans.at(s - 1) == c) {
      ans.at(s - 1) = c;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      cout << max(ans.at(i), 1);
    } else {
      cout << max(ans.at(i), 0);
    }
  }
  cout << endl;
}
