
#include <vector>
#include <iostream>
using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> num(n,0);
  bool flag = true;
  for (int i = 0; i < m; i++)
  {
    int s,c;
    cin >> s >> c;
    if (num[s-1] == 0 || num[s-1] == c) num[s-1] = c;
    else flag = false;

  }

  int ans = 0;
  if (flag == true)
  {
    for (int i = 0; i < n - 1; i++)
    {
      if (num[i] == 0)
      {
        if (n == 2) {
          flag = false;
          break;
        }
        else if (n == 3)
        {
          if (num[i - 1] == 0)
          {
            flag = false;
            break;
          }
        }
      }
    }
  }

  if (flag == false) cout << -1 << endl;
  else
  {
    for (int i = 0; i < n; i++)  ans += num[i] * pow(10, n - i - 1);
    cout << ans << endl;
  }
}