#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, s, c;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < (m); i++) {
    cin >> s >> c;
    s--;
    if (n != 1 && s == 0 && c == 0) {
      ans[0] = -2;
      break;
    } else if (ans[s] != -1 && ans[s] != c) {
      ans[0] = -2;
      break;
    } else {
      ans[s] = c;
    }
  }
  for (int i = 0; i < (n); i++) {
    if (i == 0 && ans[i] == -1)
      ans[i] = 1;
    else if (ans[i] == -1)
      ans[i] = 0;
  }
  if (ans[0] == -2)
    cout << -1 << endl;
  else
    cout << 100 * ans[0] + 10 * ans[1] + ans[2] << endl;
  return 0;
}
