#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int N, M;
  cin >> N >> M;
  string num = "";
  for (int i = 0; i < N; i++) num += "?";
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] != '?' && num[s - 1] - '0' != c) {
      cout << "-1" << endl;
      return 0;
    }
    num[s - 1] = c + '0';
  }
  if (N == 1 && num[0] == '0') {
    cout << 0 << endl;
    return 0;
  }
  for (int i = (int)pow(10, N - 1); i < (int)pow(10, N); i++) {
    string t = to_string(i);
    bool flag = true;
    for (int j = 0; j < N; j++) {
      if (t[j] == num[j] || num[j] == '?') {
      } else {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
