#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
  int n, m, s, c;
  set<int> a;
  bool ans = true;
  cin >> n >> m;
  {
    vector<int> num(n, -1);
    for (int i = 0; i < (int)(m); i++) {
      cin >> s >> c;
      if (num.at(s - 1) != -1 && num.at(s - 1) != c)
        ans = false;
      else {
        num.at(s - 1) = c;
      }
      if (s == 1 && n != 1 && c == 0) ans = false;
    }
    if (ans) {
      for (int i = 0; i < (int)(n); i++) {
        if (num.at(i) != -1)
          cout << num.at(i);
        else
          cout << 0;
      }
      cout << endl;
    } else
      cout << -1 << endl;
  }
}
