#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll x = 1e9 + 7;
const int INF = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  string ans;
  for (int i = 0; i < (n); ++i) ans.push_back('0');
  vector<bool> t(n, false);
  for (int i = 0; i < (m); ++i) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == '0') {
      cout << -1 << endl;
      return 0;
    }
    if (t[s] && ans[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ans[s] = c;
    t[s] = true;
  }
  if (ans[0] == '0') ans[0] = '1';
  cout << ans << endl;
  return 0;
}
