#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;
  bool can = true;
  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 (ans.at(s - 1) == -1 || ans.at(s - 1) == c) {
      ans.at(s - 1) = c;
    } else {
      can = false;
      break;
    }
  }
  if (ans.at(0) == 0) {
    can = false;
  }
  if (can) {
    cout << max(1, ans.at(0));
    for (int i = 1; i < N; i++) {
      cout << max(0, ans.at(i));
    }
    cout << endl;
    return 0;
  } else {
    cout << "-1" << endl;
  }
}
