#include <bits/stdc++.h>
using namespace std;
char const BLANK = '-';
int main() {
  int N, M;
  cin >> N >> M;
  bool ok = true;
  int ans = 0;
  map<int, int> m;
  for (int i = 0; i <= M - 1; ++i) {
    int s, c;
    cin >> s >> c;
    if (m.count(s) != 0 && m[s] != c)
      ok = false;
    else if (m[s] == c)
      continue;
    else {
      ans += c * pow(10, N - s);
      m[s] = c;
    }
  }
  if (N != 1 && ans < pow(10, N - 1)) ok = false;
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
