#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s, c;
  int vis[N + 1];
  fill(vis, vis + N + 1, -1);
  int ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (vis[s] == -1) {
      ans += pow(10, N - s) * c;
      vis[s] = c;
    } else {
      if (vis[s] != c) {
        ans = -1;
        break;
      }
    }
  }
  if (ans == 0 && N == 1)
    cout << 0 << endl;
  else if (ans != -1) {
    if (vis[1] == -1) ans += pow(10, N - 1);
  }
  if (ans == -1 || ans < pow(10, N - 1))
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
