#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 1001001001;
int main() {
  int N, M, i;
  bool ok = true;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> ans(N, 10);
  for (int i = 0; i < (M); ++i) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      ok = false;
    } else {
      if (ans[s[i] - 1] >= 0 && ans[s[i] - 1] < 10) {
        if (ans[s[i] - 1] != c[i]) ok = false;
      } else {
        ans[s[i] - 1] = c[i];
      }
    }
  }
  if (ok) {
    if (N == 1) {
      if (ans[0] == 10)
        cout << 0 << endl;
      else
        cout << ans[0] << endl;
    } else if (N == 2) {
      if (ans[0] == 10) {
        ans[0] = 1;
      }
      for (i = 1; i < N; i++) {
        if (ans[i] == 10) ans[i] = 0;
      }
      cout << ans[0] * 10 + ans[1] << endl;
    } else {
      if (ans[0] == 10) {
        ans[0] = 1;
      }
      for (i = 1; i < N; i++) {
        if (ans[i] == 10) ans[i] = 0;
      }
      cout << ans[0] * 100 + ans[1] * 10 + ans[2] << endl;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}
