#include <bits/stdc++.h>
using namespace std;
const long long int m = pow(10, 9) + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<int> v;
  vector<int> number(n, -1);
  while (m--) {
    int s, c;
    cin >> s >> n;
    if (number[s - 1] != -1 && number[s - 1] != c) {
      cout << "-1" << endl;
      return 0;
    }
    number[s - 1] = c;
  }
  if (number[0] == 0 && n != 1) {
    cout << "-1" << endl;
    return 0;
  } else {
    if (number[0] == -1) number[0] = (n > 1);
    for (auto digit : number) cout << max(digit, 0);
    cout << endl;
  }
  return 0;
}
