#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int pow(int a, int n) {
  int ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= a;
  }
  return ans;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> res(M, vector<int>(2));
  int ans = -1;
  int count = 0;
  for (int i = 0; i < M; i++) {
    cin >> res.at(i).at(0) >> res.at(i).at(1);
    if (res.at(i).at(0) == 1 && res.at(i).at(1) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (M == 0) {
    cout << -1 << endl;
    return 0;
  }
  int m;
  if (N == 1)
    m = 0;
  else
    m = pow(10, N - 1);
  for (int i = m; i < pow(10, N); i++) {
    count++;
    bool f = true;
    for (int j = 0; j < M; j++) {
      int a = pow(10, N - res.at(j).at(0));
      if ((i / a) % 10 != res.at(j).at(1)) {
        f = false;
        break;
      }
    }
    if (f) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
