#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    string s;
    s.append(n, ' ');
    int a;
    char b;
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      cin >> a >> b;
      if (s[a - 1] == ' ') {
        s[a - 1] = b;
      } else if (s[a - 1] == b) {
      } else {
        ans = -1;
      }
    }
    if (ans == 0) {
      if (s[0] == ' ' || s[0] == '0')
        cout << "-1";
      else if (s[1] == ' ') {
        s[1] = '0';
        cout << s;
      } else if (s[2] == ' ') {
        s[2] = '0';
        cout << s;
      }
    } else
      cout << ans;
  }
  return 0;
}
