#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 (s == 1 && c == 0) {
      ans = -1;
      break;
    }
    if (vis[s] == -1) ans += pow(10, N - s) * c;
    if (vis[s] == c || vis[s] == -1)
      vis[s] = c;
    else {
      ans = -1;
      break;
    }
  }
  if (ans == -1 || ans < pow(10, N - 1))
    cout << -1 << endl;
  else {
    if (vis[1] == -1) ans += pow(10, N - 1);
    cout << ans << endl;
  }
  return 0;
}
