#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int N, M;
  cin >> N;
  cin >> M;
  if (M == 0) {
    int ans = 0;
    if (N == 2) {
      ans = 10;
    }
    if (N == 3) {
      ans = 100;
    }
    cout << ans << endl;
    return 0;
  }
  map<int, int> mp;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s;
    cin >> c;
    if (N != 1 && s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (mp.find(s) == mp.end()) {
      mp[s] = c;
    } else {
      if (mp[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  int c = 1;
  for (int i = M; i >= 1; i--) {
    if (mp.find(i) != mp.end()) {
      ans += c * mp[i];
    }
    c *= 10;
  }
  cout << ans << endl;
  return 0;
}
