#include <bits/stdc++.h>
using namespace std;
int N, M;
int cond[4];
bool check(int n) {
  for (int i = 0; i < N; ++i) {
    if (cond[N - i - 1] != -1) {
      if ((n % 10) != cond[N - i - 1]) {
        return false;
      }
    }
    n /= 10;
  }
  return true;
}
signed main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cond[i] = -1;
  for (int i = 0; i < M; ++i) {
    int s;
    cin >> s;
    --s;
    int tmp;
    cin >> tmp;
    if (cond[s] != -1 and cond[s] != tmp) {
      cout << -1 << endl;
      return 0;
    }
    cond[s] = tmp;
    if (s == 0 and cond[s] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 1) {
    if (cond[0] < 1)
      cout << 0 << endl;
    else
      cout << cond[0] << endl;
    return 0;
  }
  int ma = 1;
  for (int i = 0; i < N; ++i) {
    ma *= 10;
  }
  for (int i = ma / 10; i < ma; ++i) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
