#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int newline() {
  putchar('\n');
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (ll i = 0; i < m; ++i) cin >> s[i] >> c[i];
  vector<int> v(n, -1);
  for (ll i = 0; i < m; ++i) {
    int itemS = s[i];
    int itemC = c[i];
    itemS--;
    if (v[itemS] != -1 && v[itemS] != itemC) {
      cout << -1 << endl;
      ;
      return 0;
    }
    v[itemS] = itemC;
  }
  const int threshold[3] = {0, 10, 100};
  int result = 0;
  for (ll i = 0; i < m; ++i) result += pow(10, n - i - 1) * max(0, v[i]);
  if (result < threshold[n - 1]) {
    cout << -1 << endl;
    ;
  } else {
    cout << result << endl;
    ;
  }
  return 0;
}
