#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int> > data(M, vector<int>(2));
  for (int i = 0; i < (int)M; i++) cin >> data[i][0] >> data[i][1];
  map<int, int> mp;
  for (int i = 0; i < (int)M; i++) {
    if (data[i][0] > N) {
      cout << "-1" << endl;
      ;
      return 0;
    }
    if (!mp.count(data[i][0])) {
      mp[data[i][0]] = data[i][1];
    } else if (mp[data[i][0]] == data[i][1]) {
      continue;
    } else {
      cout << "-1" << endl;
      ;
      return 0;
    }
  }
  int ans = 0;
  bool good = false;
  for (int i = N; i > 0; i--) {
    if (i == N && !mp.count(i)) {
      ans += (int)pow(10, i);
    }
    if (mp.count(i)) {
      if (mp[i] == 0 && (!good)) {
        cout << "-1" << endl;
        ;
        return 0;
      }
      ans += (int)pow(10, N - i) * mp[i];
      if (mp[i] != 0) {
        good = true;
      }
    }
  }
  cout << ans << endl;
  ;
  return 0;
}
