#include <bits/stdc++.h>
using namespace std;
bool isPowerOfTwo(long long n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
long long power(long long x, unsigned long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
signed main() {
  long long n, m;
  cin >> n >> m;
  long long s[m], c[m];
  for (long long i = 0; i < m; i++) cin >> s[i] >> c[i];
  long long ans[n];
  memset(ans, -1, sizeof(ans));
  long long flag = 0;
  for (long long i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0 && n != 0) flag = 1;
    if (ans[s[i] - 1] == -1 || ans[s[i] - 1] == c[i])
      ans[s[i] - 1] = c[i];
    else
      flag = 1;
  }
  if (flag == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    if (ans[0] == -1)
      cout << 0 << endl;
    else
      cout << ans[0] << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (ans[i] == -1) ans[i] = 0;
  }
  if (ans[0] == 0) ans[0] = 1;
  for (long long i = 0; i < n; i++) cout << ans[i];
}
