#include <bits/stdc++.h>
using namespace std;
using namespace std;
int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}
long comb(int n, int r) {
  long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
using namespace std;
int main() {
  int n, m;
  std::cin >> n >> m;
  int a[n + 1];
  for (int(i) = 0; (i) < (n + 1); (i)++) a[i] = 0;
  int s[m], c[m];
  for (int(i) = 0; (i) < (m); (i)++) std::cin >> s[i] >> c[i];
  for (int(i) = 0; (i) < (m); (i)++) {
    if (s[i] == 1) {
      if (c[i] == 0) {
        std::cout << -1 << std::endl;
        return 0;
      } else if (a[1] == 0)
        a[1] = c[i];
      else if (a[1] != c[i]) {
        std::cout << -1 << std::endl;
        return 0;
      }
    } else if (a[s[i]] == 0)
      a[s[i]] = c[i];
    else if (a[s[i]] != c[i]) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  if (a[1] == 0) a[1] = 1;
  int ans = 0;
  for (int(i) = 0; (i) < (n + 1); (i)++) {
    ans += a[i] * pow(10, n - i);
  }
  std::cout << ans << std::endl;
}
