#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  bool b[4] = {};
  cin >> N >> M;
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (!b[s]) {
      b[s] = true;
      if (s - N == 0) {
        if (c > 0)
          ans += c * pow(10, N - 3);
        else {
          cout << -1 << endl;
          return 0;
        }
      }
      if (s - N == -1) {
        if (c >= 0 && N != 2)
          ans += c * pow(10, N - 2);
        else {
          cout << -1 << endl;
          return 0;
        }
      }
      if (s - N == -2) {
        if (c >= 0 && N != 1)
          ans += c * pow(10, N - 1);
        else {
          cout << -1 << endl;
          return 0;
        }
      }
    } else {
      if (s == 1 && ans / 100 == c) continue;
      if (s == 2 && ans / 10 == c) continue;
      if (s == 1 && ans % 10 == c) continue;
      cout << -1 << endl;
      return 0;
    }
  }
  if (pow(10, N - 1) >= ans)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
