#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<vector<int>> num(N, vector<int>());
  size_t s = 0;
  int c = 0;
  for (int i = 0; i < M; i++) {
    cin >> s;
    cin >> c;
    if (num[s - 1].end() == find(num[s - 1].begin(), num[s - 1].end(), c)) {
      num[s - 1].push_back(c);
    }
  }
  if (num[0].size() == 0) {
    num[0].push_back(1);
  }
  int ans = 0;
  for (size_t i = 0; i < N; i++) {
    if (num[i].size() == 1) {
      ans += num[i][0] * pow(10, (N - 1 - i));
    } else if (num[i].size() == 0) {
      continue;
    } else {
      ans = -1;
      break;
    }
  }
  int minval = pow(10, (N - 1));
  if (ans < minval) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
