#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0;
int s[10], c[10], vis[10];
int main() {
  cin >> n >> m;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> s[i] >> x;
    if (x == 0 && s[i] == 1 && n != 1) {
      printf("-1\n");
      return 0;
    }
    if (vis[s[i]] && x != c[s[i]]) {
      printf("-1\n");
      return 0;
    } else {
      vis[s[i]] = 1;
      c[s[i]] = x;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      ans += c[i] * pow(10, n - i);
    else {
      if (i != 1)
        ans = ans;
      else
        ans += pow(10, n - i);
    }
  }
  printf("%d\n", ans);
  return 0;
}
