#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, si, ci, ans;
  ans = 0;
  scanf("%d%d", &n, &m);
  int num[n + 1];
  for (int i = 1; i <= n; i++) num[i] = 10;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &si, &ci);
    if (si == 1 && ci == 0 && n >= 2) continue;
    num[si] = min(num[si], ci);
  }
  for (int i = 1; i <= n; i++) {
    if (num[i] == 10) {
      num[i] = 0;
      if (i == 1) {
        ans = -1;
        break;
      }
    }
    ans += num[i] * pow(10, n - i);
  }
  printf("%d\n", ans);
}
