#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, N, M, k, ans;
  int s[5], c[5];
  int t[5], u[5];
  bool can;
  can = true;
  ans = 0;
  cin >> N >> M;
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  k = 1;
  t[0] = s[0];
  u[0] = c[0];
  for (i = 0; i < M; i++) {
    for (j = i + 1; j < M; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) can = false;
      } else {
        t[k] = s[j];
        u[k] = c[j];
        k++;
      }
    }
  }
  for (i = 0; i < k - 1; i++) {
    ans += pow(10, N - t[i]) * u[i];
  }
  if (ans < pow(10, N - 1)) can = false;
  if (can)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
