#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++)
  {
    cin >> s[i] >> c[i];
  }
  string ans;
  for (int i = 0; i < pow(10, N); i++)
  {
    bool ok = true;
    string tmp = to_string(i);
    for (int j = 0; j < M; j++)
    {
      if (tmp[s[j] - 1] != c[j])
        ok = false;
      if ((N == 2 or N == 3) && s[j] == 1 && c[j] == '0')
      {
        cout << -1 << endl;
        return;
      }
    }
    if (ok)
    {
      ans = tmp;
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
