#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int si[M];
  int ci[M];
  for (int i = (0); i < (M); ++i) {
    cin >> si[i] >> ci[i];
  }
  vector<int> result(N, 0);
  vector<bool> changed(N, false);
  if (M == 0) {
    if (N == 1) {
      cout << "0" << endl;
      return 0;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = (0); i < (M); ++i) {
    if (si[i] > N) {
      cout << "-1" << endl;
      return 0;
    }
    int index = si[i] - 1;
    if (changed[index]) {
      if (result[index] != ci[i]) {
        cout << "-1" << endl;
        return 0;
      }
    }
    result[index] = ci[i];
    changed[index] = true;
  }
  if (N == 1 && result[0] == 0) {
    cout << "0" << endl;
    return 0;
  }
  bool blAllZero = true;
  if (N > 1) {
    for (int i = (0); i < (N); ++i) {
      blAllZero &= (result[i] == 0);
    }
  }
  if (N != 1 && blAllZero) {
    cout << "-1" << endl;
    return 0;
  }
  if (N != 1 & result[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  string ans = "";
  for (int i = (0); i < (N); ++i) {
    ans += to_string(result[i]);
  }
  cout << ans << endl;
  return 0;
}
