#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  vector<int> c(n, 0);
  for (int i = 0; i < n; i++) {
    if (b[i] == 0 && a[i] == 1 && n != 1) {
      cout << -1 << endl;
      break;
    }
    if (b[i] == 0 && a[i] == 1 && n == 1) {
      cout << 0 << endl;
      break;
    }
    c[a[i] - 1] = b[i];
    if (i == n - 1) {
      if (c[0] == 0) {
        c[0] = 1;
      }
      int d = 0, e = 0;
      for (int j = 0; j < n; j++) {
        if (b[j] != c[a[j] - 1]) {
          cout << -1 << endl;
          d = c[a[j] - 1];
          e = j;
          break;
        }
      }
      if (b[e] != d && d != 0 && e != 0) {
        break;
      }
      int ans = 0;
      for (int j = 0; j < n; j++) {
        ans += c[j] * (pow(10, n - j - 1));
        if (j == n - 1) {
          cout << ans << endl;
        }
      }
    }
  }
}
