#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  vector<int> a(3, 10);
  for (int i = 0; i < (int)(m); i++) {
    a[s[i] - 1] = min(a[s[i] - 1], c[i]);
  }
  int b = 1;
  for (int i = 0; i < (int)(n - 1); i++) b *= 10;
  for (int i = 0; i < (int)(n); i++)
    if (a[i] == 10) a[i] = 0;
  int ans = a[0] * 100 + a[1] * 10 + a[2];
  if (b > ans) ans = -1;
  cout << ans << endl;
  return 0;
}
