#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> num(N);
  vector<bool> settled(N);
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if ((settled[s] && c != num[s]) || (s > N)) {
      num[0] = 0;
      break;
    }
    settled[s] = true;
    num[s] = c;
  }
  if (num[0] == 0)
    cout << -1;
  else {
    for (int i = 0; i < (N); ++i) cout << num[i];
    cout << endl;
  }
}
