#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int vis[n];
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (vis[s] != -1 && vis[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    vis[s] = c;
  }
  int j = 0;
  while (j < n && vis[j] == 0) j++;
  if (j && n > 1) return cout << -1 << endl, 0;
  for (int i = 0; i < n; i++) {
    if (vis[i] != -1)
      cout << vis[i];
    else if (i > 0)
      cout << 0;
    else
      cout << 1;
  }
  cout << endl;
  return 0;
}
