#include <bits/stdc++.h>
using namespace std;
int visited[105];
int main() {
  int n, m;
  cin >> n >> m;
  string ans = "";
  for (int i = 1; i <= n; ++i) ans += '0';
  memset(visited, -1, sizeof visited);
  bool ok = true;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (~visited[s] && visited[s] != c) ok = true;
    visited[s] = c;
    ans[s - 1] = (c + '0');
  }
  int temp = stoi(ans);
  string temp2 = to_string(temp);
  if ((temp2 != ans) || !ok)
    cout << -1;
  else
    cout << ans;
}
